[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d434071 120/167: swiper.el (swiper-all): New command to sw
From: |
Oleh Krehel |
Subject: |
[elpa] master d434071 120/167: swiper.el (swiper-all): New command to swiper all file buffers |
Date: |
Tue, 08 Dec 2015 10:50:26 +0000 |
branch: master
commit d434071ff4ba1034751c4b2462720bb28cdb7018
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper-all): New command to swiper all file buffers
* swiper.el (swiper--candidates): Add NUMBERS-WIDTH arg. It could be
done better by calculating the line count of each buffer and then
getting the max of that, but this way is faster, since the collections
are traversed only once.
(swiper-multi): Update.
(swiper-all): New command. This is like `swiper-multi' where the buffer
list is pre-selected to be all file visiting buffers.
(swiper--multi-candidates): New defun.
(swiper-multi-action-1): Use `swiper--multi-candidates'.
(swiper-multi-action-2): Update - the line number is in the 'display
property of the first char.
Re #234
---
swiper.el | 84 +++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/swiper.el b/swiper.el
index 15d5478..56247ed 100644
--- a/swiper.el
+++ b/swiper.el
@@ -244,15 +244,20 @@
(defvar swiper-use-visual-line nil
"When non-nil, use `line-move' instead of `forward-line'.")
-(defun swiper--candidates ()
- "Return a list of this buffer lines."
+(defun swiper--candidates (&optional numbers-width)
+ "Return a list of this buffer lines.
+
+NUMBERS-WIDTH, when specified, is used for line numbers width
+spec, instead of calculating it as the log of the buffer line
+count."
(setq swiper-use-visual-line
(and (not (eq major-mode 'org-mode))
visual-line-mode
(< (buffer-size) 20000)))
(let ((n-lines (count-lines (point-min) (point-max))))
(unless (zerop n-lines)
- (setq swiper--width (1+ (floor (log n-lines 10))))
+ (setq swiper--width (or numbers-width
+ (1+ (floor (log n-lines 10)))))
(setq swiper--format-spec
(format "%%-%dd " swiper--width))
(let ((line-number 0)
@@ -537,7 +542,6 @@ WND, when specified is the window."
Run `swiper' for those buffers."
(interactive)
(setq swiper-multi-buffers nil)
- (setq swiper-multi-candidates nil)
(ivy-read (swiper-multi-prompt)
'internal-complete-buffer
:action 'swiper-multi-action-1)
@@ -546,6 +550,48 @@ Run `swiper' for those buffers."
:unwind #'swiper--cleanup
:caller 'swiper-multi))
+(defun swiper-all ()
+ "Run `swiper' for all opened buffers."
+ (interactive)
+ (ivy-read "Swiper: " (swiper--multi-candidates
+ (cl-remove-if-not
+ #'buffer-file-name
+ (buffer-list)))
+ :action 'swiper-multi-action-2
+ :unwind #'swiper--cleanup
+ :caller 'swiper-multi))
+
+(defun swiper--multi-candidates (buffers)
+ (let* ((ww (window-width))
+ (res nil)
+ (column-2 (apply #'max
+ (mapcar
+ (lambda (b)
+ (length (buffer-name b)))
+ buffers)))
+ (column-1 (- ww 4 column-2 1)))
+ (dolist (buf buffers)
+ (with-current-buffer buf
+ (setq res
+ (append
+ (mapcar
+ (lambda (s)
+ (setq s (concat (ivy--truncate-string s column-1) " "))
+ (let ((len (length s)))
+ (put-text-property
+ (1- len) len 'display
+ (concat
+ (make-string
+ (- ww (string-width s) (length (buffer-name)) 3)
+ ?\ )
+ (buffer-name))
+ s)
+ s))
+ (swiper--candidates 4))
+ res))
+ nil))
+ res))
+
(defun swiper-multi-action-1 (x)
(if (member x swiper-multi-buffers)
(progn
@@ -558,31 +604,9 @@ Run `swiper' for those buffers."
(cond ((memq this-command '(ivy-done
ivy-alt-done
ivy-immediate-done))
- (let ((ww (window-width)))
- (dolist (buf swiper-multi-buffers)
- (with-current-buffer buf
- (setq swiper-multi-candidates
- (append
- (mapcar
- (lambda (s)
- (setq s (concat s " "))
- (let ((len (length s)))
- (put-text-property
- (1- len) len 'display
- (concat
- (make-string
- (max
- (- ww
- (string-width s)
- (length (buffer-name))
- 1)
- 0)
- ?\ )
- (buffer-name))
- s)
- s))
- (swiper--candidates))
- swiper-multi-candidates))))))
+ (setq swiper-multi-candidates
+ (swiper--multi-candidates
+ (mapcar #'get-buffer swiper-multi-buffers))))
((eq this-command 'ivy-call)
(delete-minibuffer-contents))))
@@ -592,7 +616,7 @@ Run `swiper' for those buffers."
(when (string-match "\\` *\\([^ ]+\\)\\'" buf-space)
(switch-to-buffer (match-string 1 buf-space))
(goto-char (point-min))
- (forward-line (1- (read x)))
+ (forward-line (1- (read (get-text-property 0 'display x))))
(re-search-forward
(ivy--regex ivy-text)
(line-end-position) t)
- [elpa] master 7cf7575 103/167: swiper.el (swiper-toggle-face-matching): Add and bind to "C-c C-f", (continued)
- [elpa] master 7cf7575 103/167: swiper.el (swiper-toggle-face-matching): Add and bind to "C-c C-f", Oleh Krehel, 2015/12/08
- [elpa] master 6b612cf 093/167: Rebind ivy-occur to "C-c C-o" and "C-o u", Oleh Krehel, 2015/12/08
- [elpa] master 4544c69 105/167: ivy.el (ivy-dispatching-done): Don't set action permanently, Oleh Krehel, 2015/12/08
- [elpa] master e037fb0 101/167: counsel.el (counsel-M-x): Show current-prefix-arg in the prompt, Oleh Krehel, 2015/12/08
- [elpa] master dcc747b 107/167: ivy.el (ivy-occur-mode-map): Bind "q" to quit-window, Oleh Krehel, 2015/12/08
- [elpa] master 57800f6 110/167: swiper.el (swiper-font-lock-ensure): Add eww-mode, Oleh Krehel, 2015/12/08
- [elpa] master f246178 113/167: ivy.el (ivy-prefix-sort): New defcustom, off by default for now, Oleh Krehel, 2015/12/08
- [elpa] master 660e293 106/167: Allow counsel-git-grep -> ivy-occur -> wgrep, Oleh Krehel, 2015/12/08
- [elpa] master 044307d 116/167: ivy.el (ivy--sort-files-by-date): Fix due to destructive cl-sort, Oleh Krehel, 2015/12/08
- [elpa] master 6666cf8 099/167: Fix directory validity check, Oleh Krehel, 2015/12/08
- [elpa] master d434071 120/167: swiper.el (swiper-all): New command to swiper all file buffers,
Oleh Krehel <=
- [elpa] master b39e20c 102/167: ivy.el (ivy-alt-done): Ensure the trailing slash for directories, Oleh Krehel, 2015/12/08
- [elpa] master d89abf2 104/167: counsel.el (counsel--find-symbol): Silence byte compiler, Oleh Krehel, 2015/12/08
- [elpa] master c4562e0 109/167: swiper.el (swiper-font-lock-ensure): Add occur-mode, Oleh Krehel, 2015/12/08
- [elpa] master 5d90542 112/167: ivy.el (ivy-sort-functions-alist): Update doc, Oleh Krehel, 2015/12/08
- [elpa] master adac116 126/167: Make ivy-completing-read handle history as cons, Oleh Krehel, 2015/12/08
- [elpa] master c580fe9 108/167: ivy.el (ivy-occur): Give full counsel-git-grep cands, Oleh Krehel, 2015/12/08
- [elpa] master bb68b67 122/167: Intermediate fix for :preselect with visual-line-mode, Oleh Krehel, 2015/12/08
- [elpa] master 5751119 124/167: README.md: Add more bindings, Oleh Krehel, 2015/12/08
- [elpa] master e47ec14 128/167: ivy.el (ivy-completing-read): Fix off by one, Oleh Krehel, 2015/12/08
- [elpa] master d5489af 100/167: doc/ivy.org: Start writing a manual, Oleh Krehel, 2015/12/08