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

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

[elpa] externals/ivy-hydra b91a4e2 238/395: counsel.el (counsel--git-gre


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra b91a4e2 238/395: counsel.el (counsel--git-grep-index): Add
Date: Thu, 25 Feb 2021 08:32:10 -0500 (EST)

branch: externals/ivy-hydra
commit b91a4e29960df95f7690364886c78dc93c45cc38
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    counsel.el (counsel--git-grep-index): Add
---
 counsel.el | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/counsel.el b/counsel.el
index 60f144d..dd66db5 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1528,10 +1528,29 @@ When CMD is non-nil, prompt for a specific \"git grep\" 
command."
                 :require-match t
                 :caller 'counsel-git-grep))))
 
+(defun counsel--git-grep-index (_re-str cands)
+  (if (null ivy--old-cands)
+      (let ((ln (with-ivy-window
+                  (line-number-at-pos)))
+            (name (file-name-nondirectory (with-ivy-window 
(buffer-file-name)))))
+        (or
+         ;; closest to current line going forwards
+         (cl-position-if (lambda (x)
+                           (and (string-prefix-p name x)
+                                (>= (string-to-number
+                                     (substring x (1+ (length name)))) ln)))
+                         cands)
+         ;; closest to current line going backwards
+         (cl-position-if (lambda (x)
+                           (string-prefix-p name x))
+                         cands
+                         :from-end t)))
+    (ivy-recompute-index-swiper-async nil cands)))
+
 (ivy-configure 'counsel-git-grep
   :occur #'counsel-git-grep-occur
   :unwind-fn #'counsel--grep-unwind
-  :index-fn #'ivy-recompute-index-swiper-async
+  :index-fn #'counsel--git-grep-index
   :display-transformer-fn #'counsel-git-grep-transformer
   :grep-p t
   :exit-codes '(1 "No matches found"))



reply via email to

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