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

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

[elpa] externals/ivy-hydra 71f5727 261/395: counsel.el (counsel--git-gre


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra 71f5727 261/395: counsel.el (counsel--git-grep-index): Don't error on null buffer-file-name
Date: Thu, 25 Feb 2021 08:32:16 -0500 (EST)

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

    counsel.el (counsel--git-grep-index): Don't error on null buffer-file-name
    
    Fixes #2543
---
 counsel.el | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/counsel.el b/counsel.el
index 9121aa0..87c1262 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1567,21 +1567,24 @@ When CMD is non-nil, prompt for a specific \"git grep\" 
command."
 
 (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)))
+      (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)))
 
 (ivy-configure 'counsel-git-grep



reply via email to

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