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

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

[elpa] externals/ivy-hydra 84efa3a 262/395: Ensure counsel--git-grep-ind


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra 84efa3a 262/395: Ensure counsel--git-grep-index returns non-nil
Date: Thu, 25 Feb 2021 08:32:16 -0500 (EST)

branch: externals/ivy-hydra
commit 84efa3a2cbb9c5b0bbcc8d2e90671434eed74f94
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Ensure counsel--git-grep-index returns non-nil
    
    * counsel.el (counsel--git-grep-index): Return a valid non-nil index
    even when all the calls to cl-position-if return nil.
    
    Re: #2543
---
 counsel.el | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/counsel.el b/counsel.el
index 87c1262..f22976a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1566,26 +1566,27 @@ When CMD is non-nil, prompt for a specific \"git grep\" 
command."
                 :caller 'counsel-git-grep))))
 
 (defun counsel--git-grep-index (_re-str cands)
-  (if (null ivy--old-cands)
-      (let ((bname (with-ivy-window (buffer-file-name))))
-        (if bname
-            (let ((ln (with-ivy-window
-                        (line-number-at-pos)))
-                  (name (file-name-nondirectory bname)))
-              (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)))
-          0))
-    (ivy-recompute-index-swiper-async nil cands)))
+  (let (name ln)
+    (cond
+      (ivy--old-cands
+       (ivy-recompute-index-swiper-async nil cands))
+      ((unless (with-ivy-window
+                 (when buffer-file-name
+                   (setq ln (line-number-at-pos))
+                   (setq name (file-name-nondirectory buffer-file-name))))
+         0))
+      ;; Closest to current line going forwards.
+      ((let ((beg (1+ (length name))))
+         (cl-position-if (lambda (x)
+                           (and (string-prefix-p name x)
+                                (>= (string-to-number (substring x beg)) ln)))
+                         cands)))
+      ;; Closest to current line going backwards.
+      ((cl-position-if (lambda (x)
+                         (string-prefix-p name x))
+                       cands
+                       :from-end t))
+      (t 0))))
 
 (ivy-configure 'counsel-git-grep
   :occur #'counsel-git-grep-occur



reply via email to

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