]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel-grep should pick candidates closest to point
authorOleh Krehel <ohwoeowho@gmail.com>
Wed, 6 Apr 2016 17:36:41 +0000 (19:36 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Wed, 6 Apr 2016 17:36:41 +0000 (19:36 +0200)
* ivy.el (ivy-recompute-index-swiper-async): Update.

Fixes the algorithm selecting the first matching candidate in case there
are 0 matching candidates following point. Now the last matching
candidate will be selected, resulting in less scrolling.

ivy.el

diff --git a/ivy.el b/ivy.el
index 415f54a6892277cc0f67b66b4253b007c1b642ee..16e7d7fce2e9608c23d4667701e0ca2be48a913d 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -2242,10 +2242,13 @@ Prefix matches to NAME are put ahead of the list."
   (if (null ivy--old-cands)
       (let ((ln (with-ivy-window
                   (line-number-at-pos))))
-        (or (cl-position-if (lambda (x)
-                              (>= (string-to-number x) ln))
-                            cands)
-            0))
+        (or
+         ;; closest to current line going forwards
+         (cl-position-if (lambda (x)
+                           (>= (string-to-number x) ln))
+                         cands)
+         ;; closest to current line going backwards
+         (1- (length cands))))
     (let ((tail (nthcdr ivy--index ivy--old-cands))
           idx)
       (if (and tail ivy--old-cands (not (equal "^" ivy--old-re)))