]> code.delx.au - gnu-emacs-elpa/commitdiff
Improve swiper for multiple occurrences on one line
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 12 Dec 2015 08:41:07 +0000 (09:41 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 12 Dec 2015 08:41:07 +0000 (09:41 +0100)
* 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

index d9bf724cf16a5228564bf422d871e7775ec75cf6..bb20ab413b3170f9b628defcfc0776670e0675c6 100644 (file)
--- 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))