]> code.delx.au - gnu-emacs-elpa/blobdiff - ivy.el
counsel-grep should pick candidates closest to point
[gnu-emacs-elpa] / 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)))