branch: master
commit 1489b5280ba307fb076e2a0e211bbf25d4c278ed
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-git-grep): Fix error on 24.5
Fixes #1107
---
counsel.el | 59 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/counsel.el b/counsel.el
index dcb8c79..29ea418 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1149,34 +1149,40 @@ Typical value: '(recenter)."
Allows to automatically use a custom \"git-grep\" command for all
files in a project.")
-;;;###autoload
-(defun counsel-git-grep (&optional cmd initial-input)
- "Grep for a string in the current git repository.
-When CMD is a string, use it as a \"git grep\" command.
-When CMD is non-nil, prompt for a specific \"git grep\" command.
-INITIAL-INPUT can be given as the initial minibuffer input."
- (interactive "P")
- (ivy-set-prompt 'counsel-git-grep counsel-prompt-function)
+(defun counsel--git-grep-cmd-and-proj (cmd)
(let ((dd (expand-file-name default-directory))
proj)
(cond
- ((stringp cmd)
- (setq counsel-git-grep-cmd cmd))
+ ((stringp cmd))
(cmd
(if (setq proj
(cl-find-if
(lambda (x)
(string-match (car x) dd))
counsel-git-grep-projects-alist))
- (setq counsel-git-grep-cmd (cdr proj))
- (setq counsel-git-grep-cmd
+ (setq cmd (cdr proj))
+ (setq cmd
(ivy-read "cmd: " counsel-git-grep-cmd-history
:history 'counsel-git-grep-cmd-history
:re-builder #'ivy--regex))
(setq counsel-git-grep-cmd-history
(delete-dups counsel-git-grep-cmd-history))))
(t
- (setq counsel-git-grep-cmd counsel-git-grep-cmd-default)))
+ (setq cmd counsel-git-grep-cmd-default)))
+ (cons proj cmd)))
+
+;;;###autoload
+(defun counsel-git-grep (&optional cmd initial-input)
+ "Grep for a string in the current git repository.
+When CMD is a string, use it as a \"git grep\" command.
+When CMD is non-nil, prompt for a specific \"git grep\" command.
+INITIAL-INPUT can be given as the initial minibuffer input."
+ (interactive "P")
+ (ivy-set-prompt 'counsel-git-grep counsel-prompt-function)
+ (let ((proj-and-cmd (counsel--git-grep-cmd-and-proj cmd))
+ proj)
+ (setq proj (car proj-and-cmd))
+ (setq counsel-git-grep-cmd (cdr proj-and-cmd))
(counsel-require-program (car (split-string counsel-git-grep-cmd)))
(setq counsel--git-grep-dir
(if proj
@@ -1189,25 +1195,24 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
(if (eq system-type 'windows-nt)
0
(counsel--gg-count "" t))))
- (cl-flet
- ((collection-function
- (if proj
- #'counsel-git-grep-proj-function
- #'counsel-git-grep-function))
- (unwind-function
- (if proj
- (lambda ()
- (counsel-delete-process)
- (swiper--cleanup))
- (lambda ()
- (swiper--cleanup)))))
- (ivy-read "git grep" #'collection-function
+ (let ((collection-function
+ (if proj
+ #'counsel-git-grep-proj-function
+ #'counsel-git-grep-function))
+ (unwind-function
+ (if proj
+ (lambda ()
+ (counsel-delete-process)
+ (swiper--cleanup))
+ (lambda ()
+ (swiper--cleanup)))))
+ (ivy-read "git grep" collection-function
:initial-input initial-input
:matcher #'counsel-git-grep-matcher
:dynamic-collection (or proj
counsel-git-grep-skip-counting-lines (> counsel--git-grep-count 20000))
:keymap counsel-git-grep-map
:action #'counsel-git-grep-action
- :unwind #'unwind-function
+ :unwind unwind-function
:history 'counsel-git-grep-history
:caller 'counsel-git-grep)))))