]> code.delx.au - gnu-emacs-elpa/commitdiff
swiper.el (swiper--update-input-ivy): Add a work-around for "M-j"
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 4 Dec 2015 07:30:17 +0000 (08:30 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 4 Dec 2015 07:31:42 +0000 (08:31 +0100)
When `ivy-yank-word' is called, don't move to the line of the current
candidate. We're already there anyway. And not moving helps when there
are multiple occurrences of the current input on the current line.

Fixes #314

swiper.el

index 593f7633549171a798f6fd11d9ea1cc79ba4f79c..2ee60a3a7a67c0d772e1bbb2c8a79917fd14bedc 100644 (file)
--- a/swiper.el
+++ b/swiper.el
@@ -258,7 +258,8 @@ count."
           (require 'outline)
           (if (fboundp 'outline-show-all)
               (outline-show-all)
-            (show-all)))
+            (with-no-warnings
+              (show-all))))
         (setq swiper-use-visual-line t))
     (setq swiper-use-visual-line nil))
   (let ((n-lines (count-lines (point-min) (point-max))))
@@ -437,22 +438,23 @@ Matched candidates should have `swiper-invocation-face'."
              (num (if (string-match "^[0-9]+" str)
                       (string-to-number (match-string 0 str))
                     0)))
-        (goto-char (point-min))
-        (when (cl-plusp num)
+        (unless (eq this-command 'ivy-yank-word)
           (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))
-          (isearch-range-invisible (line-beginning-position)
-                                   (line-end-position))
-          (unless (and (>= (point) (window-start))
-                       (<= (point) (window-end (ivy-state-window ivy-last) t)))
-            (recenter)))
+          (when (cl-plusp 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))
+            (isearch-range-invisible (line-beginning-position)
+                                     (line-end-position))
+            (unless (and (>= (point) (window-start))
+                         (<= (point) (window-end (ivy-state-window ivy-last) t)))
+              (recenter))))
         (swiper--add-overlays re)))))
 
 (defun swiper--add-overlays (re &optional beg end wnd)