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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 83f89d8 003/272: Improve swiper for multiple occurrences o


From: Oleh Krehel
Subject: [elpa] master 83f89d8 003/272: Improve swiper for multiple occurrences on one line
Date: Mon, 25 Apr 2016 10:13:13 +0000

branch: master
commit 83f89d8c3160b968a422127d14d245f3f4a2c733
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Improve swiper for multiple occurrences on one line
    
    * swiper.el (swiper--current-line):
    (swiper--current-match-start): New defvar.
    (swiper--init): Update.
    (swiper--update-input-ivy): Don't move to line NUM if
    `swiper--current-line' is equal to NUM. Later, store NUM in
    `swiper--current-line' to avoid calling `line-number-at-pos'.
    Additionally store `swiper--current-match-start' - it's necessary to
    move there before searching for the regexp, since the point currently is
    after the old regexp.
    
    Fixes #314
---
 swiper.el |   24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/swiper.el b/swiper.el
index d9bf724..bb20ab4 100644
--- a/swiper.el
+++ b/swiper.el
@@ -315,8 +315,13 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
 
 (declare-function evil-jumper--set-jump "ext:evil-jumper")
 
+(defvar swiper--current-line nil)
+(defvar swiper--current-match-start nil)
+
 (defun swiper--init ()
   "Perform initialization common to both completion methods."
+  (setq swiper--current-line nil)
+  (setq swiper--current-match-start nil)
   (setq swiper--opoint (point))
   (when (bound-and-true-p evil-jumper-mode)
     (evil-jumper--set-jump)))
@@ -440,17 +445,24 @@ Matched candidates should have `swiper-invocation-face'."
                       (string-to-number (match-string 0 str))
                     0)))
         (unless (eq this-command 'ivy-yank-word)
-          (goto-char (point-min))
           (when (cl-plusp num)
-            (goto-char (point-min))
-            (if swiper-use-visual-line
-                (line-move (1- num))
-              (forward-line (1- num)))
+            (unless (if swiper--current-line
+                        (eq swiper--current-line num)
+                      (eq (line-number-at-pos) num))
+              (goto-char (point-min))
+              (if swiper-use-visual-line
+                  (line-move (1- num))
+                (forward-line (1- num))))
             (if (and (equal ivy-text "")
                      (>= swiper--opoint (line-beginning-position))
                      (<= swiper--opoint (line-end-position)))
                 (goto-char swiper--opoint)
-              (re-search-forward re (line-end-position) t))
+              (if (eq swiper--current-line num)
+                  (when swiper--current-match-start
+                    (goto-char swiper--current-match-start))
+                (setq swiper--current-line num))
+              (re-search-forward re (line-end-position) t)
+              (setq swiper--current-match-start (match-beginning 0)))
             (isearch-range-invisible (line-beginning-position)
                                      (line-end-position))
             (unless (and (>= (point) (window-start))



reply via email to

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