emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]