[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3e651a3 116/348: Make swiper-all use point positions inste
From: |
Oleh Krehel |
Subject: |
[elpa] master 3e651a3 116/348: Make swiper-all use point positions instead of line positions |
Date: |
Sat, 8 Apr 2017 11:03:39 -0400 (EDT) |
branch: master
commit 3e651a307e4e2435dcd18e6fd57759e99f21f3ea
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Make swiper-all use point positions instead of line positions
* swiper.el (swiper-all-function): Using point positions speeds up the
whole thing by a huge amount. It's a bit less pretty than with the
line positions though.
Remove text properties from `org-mode', otherwise I don't know how to
align those strings.
(swiper-all-action): Separate action.
---
swiper.el | 111 +++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 63 insertions(+), 48 deletions(-)
diff --git a/swiper.el b/swiper.el
index 713e11c..76e182f 100644
--- a/swiper.el
+++ b/swiper.el
@@ -670,9 +670,45 @@ Run `swiper' for those buffers."
:unwind #'swiper--cleanup
:caller 'swiper-multi))
+(defun swiper-multi-action-1 (x)
+ (if (member x swiper-multi-buffers)
+ (progn
+ (setq swiper-multi-buffers (delete x swiper-multi-buffers)))
+ (unless (equal x "")
+ (setq swiper-multi-buffers (append swiper-multi-buffers (list x)))))
+ (let ((prompt (swiper-multi-prompt)))
+ (setf (ivy-state-prompt ivy-last) prompt)
+ (setq ivy--prompt (concat "%-4d " prompt)))
+ (cond ((memq this-command '(ivy-done
+ ivy-alt-done
+ ivy-immediate-done))
+ (setq swiper-multi-candidates
+ (swiper--multi-candidates
+ (mapcar #'get-buffer swiper-multi-buffers))))
+ ((eq this-command 'ivy-call)
+ (delete-minibuffer-contents))))
+
+(defun swiper-multi-action-2 (x)
+ (when (> (length x) 0)
+ (let ((buffer-name (get-text-property 0 'buffer x)))
+ (when buffer-name
+ (with-ivy-window
+ (switch-to-buffer buffer-name)
+ (goto-char (point-min))
+ (forward-line (1- (read (get-text-property 0 'swiper-line-number
x))))
+ (re-search-forward
+ (ivy--regex ivy-text)
+ (line-end-position) t)
+ (isearch-range-invisible (line-beginning-position)
+ (line-end-position))
+ (unless (eq ivy-exit 'done)
+ (swiper--cleanup)
+ (swiper--add-overlays (ivy--regex ivy-text))))))))
+
+;;* `swiper-all'
(defun swiper-all-function (str)
(if (and (< (length str) 3))
- (counsel-more-chars 3)
+ (list "" (format "%d chars more" (- 3 (length ivy-text))))
(let ((buffers (cl-remove-if-not
(lambda (b)
(or (buffer-file-name b)
@@ -687,19 +723,20 @@ Run `swiper' for those buffers."
(save-excursion
(goto-char (point-min))
(while (re-search-forward re nil t)
- (setq match (concat
- " "
- (buffer-substring
- (line-beginning-position)
- (line-end-position))))
+ (setq match (if (memq major-mode '(org-mode dired-mode))
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))
+ (buffer-substring
+ (line-beginning-position)
+ (line-end-position))))
(put-text-property
0 1 'buffer
(buffer-name)
match)
- (let ((lns (format "%-4d " (line-number-at-pos))))
- (put-text-property 0 1 'swiper-line-number lns match)
- (put-text-property 0 1 'display lns match))
+ (put-text-property 0 1 'point (point) match)
(push match cands)))))
+ (setq ivy--old-re nil)
(setq ivy--old-cands (nreverse cands)))))
(defun swiper--all-format-function (cands)
@@ -710,7 +747,7 @@ Run `swiper' for those buffers."
(let ((buffer (get-text-property 0 'buffer s)))
(setq col2 (max col2 (length buffer)))
(cons s buffer))) cands))
- (col1 (- ww 6 col2)))
+ (col1 (- ww 4 col2)))
(setq cands
(mapcar (lambda (x)
(if (cdr x)
@@ -719,7 +756,7 @@ Run `swiper' for those buffers."
s
(make-string
(max 0
- (- ww (string-width s) (length (cdr x)) 4))
+ (- ww (string-width s) (length (cdr x))))
?\ )
(cdr x)))
(car x)))
@@ -737,13 +774,26 @@ Run `swiper' for those buffers."
(interactive)
(let ((ivy-format-function #'swiper--all-format-function))
(ivy-read "Swiper: " 'swiper-all-function
- :action 'swiper-multi-action-2
+ :action 'swiper-all-action
:unwind #'swiper--cleanup
:update-fn (lambda ()
- (swiper-multi-action-2 ivy--current))
+ (swiper-all-action ivy--current))
:dynamic-collection t
:caller 'swiper-multi)))
+(defun swiper-all-action (x)
+ (when (> (length x) 0)
+ (let ((buffer-name (get-text-property 0 'buffer x)))
+ (when buffer-name
+ (with-ivy-window
+ (switch-to-buffer buffer-name)
+ (goto-char (get-text-property 0 'point x))
+ (isearch-range-invisible (line-beginning-position)
+ (line-end-position))
+ (unless (eq ivy-exit 'done)
+ (swiper--cleanup)
+ (swiper--add-overlays (ivy--regex ivy-text))))))))
+
(defun swiper--multi-candidates (buffers)
(let* ((ww (window-width))
(res nil)
@@ -776,41 +826,6 @@ Run `swiper' for those buffers."
nil))
res))
-(defun swiper-multi-action-1 (x)
- (if (member x swiper-multi-buffers)
- (progn
- (setq swiper-multi-buffers (delete x swiper-multi-buffers)))
- (unless (equal x "")
- (setq swiper-multi-buffers (append swiper-multi-buffers (list x)))))
- (let ((prompt (swiper-multi-prompt)))
- (setf (ivy-state-prompt ivy-last) prompt)
- (setq ivy--prompt (concat "%-4d " prompt)))
- (cond ((memq this-command '(ivy-done
- ivy-alt-done
- ivy-immediate-done))
- (setq swiper-multi-candidates
- (swiper--multi-candidates
- (mapcar #'get-buffer swiper-multi-buffers))))
- ((eq this-command 'ivy-call)
- (delete-minibuffer-contents))))
-
-(defun swiper-multi-action-2 (x)
- (when (> (length x) 0)
- (let ((buffer-name (get-text-property 0 'buffer x)))
- (when buffer-name
- (with-ivy-window
- (switch-to-buffer buffer-name)
- (goto-char (point-min))
- (forward-line (1- (read (get-text-property 0 'swiper-line-number
x))))
- (re-search-forward
- (ivy--regex ivy-text)
- (line-end-position) t)
- (isearch-range-invisible (line-beginning-position)
- (line-end-position))
- (unless (eq ivy-exit 'done)
- (swiper--cleanup)
- (swiper--add-overlays (ivy--regex ivy-text))))))))
-
(provide 'swiper)
;;; swiper.el ends here
- [elpa] master fc2e198 335/348: swiper.el (swiper--action): Set evil search direction to forward, (continued)
- [elpa] master fc2e198 335/348: swiper.el (swiper--action): Set evil search direction to forward, Oleh Krehel, 2017/04/08
- [elpa] master 718a06b 345/348: doc/Changelog.org: Fix links, Oleh Krehel, 2017/04/08
- [elpa] master 802c9da 271/348: counsel.el: Add counsel-command-history, Oleh Krehel, 2017/04/08
- [elpa] master ee91a25 283/348: ivy.el (ivy--sort-maybe): Fix byte-compiler warning, Oleh Krehel, 2017/04/08
- [elpa] master dc693c3 280/348: Make ivy--flx-sort more intelligent, Oleh Krehel, 2017/04/08
- [elpa] master 182e35e 298/348: Apply search highlighting for evil when applicable, Oleh Krehel, 2017/04/08
- [elpa] master aedea1a 289/348: counsel.el (counsel-package): Add func to manage packages., Oleh Krehel, 2017/04/08
- [elpa] master b9c52be 301/348: counsel.el (counsel-git): Add "x" action, Oleh Krehel, 2017/04/08
- [elpa] master dbeb5b1 303/348: Ensure counsel-M-x preserves last-command, Oleh Krehel, 2017/04/08
- [elpa] master ae3ca26 117/348: counsel.el (counsel-locate-action-extern): Add w32 support, Oleh Krehel, 2017/04/08
- [elpa] master 3e651a3 116/348: Make swiper-all use point positions instead of line positions,
Oleh Krehel <=
- [elpa] master ef3f010 128/348: ivy.el (ivy--insert-prompt): Improve the extra "\n" logic, Oleh Krehel, 2017/04/08
- [elpa] master 870112e 176/348: counsel.el (counsel-ag-function): Use sync on remote, Oleh Krehel, 2017/04/08
- [elpa] master 1914ecd 203/348: counsel.el (counsel-recoll-function): Add shell-quote-argument, Oleh Krehel, 2017/04/08
- [elpa] master f0e49d5 213/348: Improve recursive minibuffers with two emacsclients, Oleh Krehel, 2017/04/08
- [elpa] master df9ad89 220/348: counsel.el (counsel-rpm): New command, Oleh Krehel, 2017/04/08
- [elpa] master aea4919 225/348: Shrink ivy back to ivy-height after dispatching actions., Oleh Krehel, 2017/04/08
- [elpa] master 88bf299 228/348: counsel.el (counsel-recentf): Remove properties from recentf-list, Oleh Krehel, 2017/04/08
- [elpa] master 576a1e3 232/348: Revert "ivy.el (ivy-call): setq default-directory instead of let", Oleh Krehel, 2017/04/08
- [elpa] master 50bb6b3 250/348: ivy.el (ivy-call): Call the action in ivy-state-buffer, Oleh Krehel, 2017/04/08
- [elpa] master f9f2c8c 251/348: counsel.el (counsel-bookmark-avoid-dired): Add, Oleh Krehel, 2017/04/08