branch: master
commit da7eb943a8e07607a1bd148a9c3a55a7e74f1ebe
Author: Basil L. Contovounesios <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-grep-base-command): Improve docs & usage
(counsel-grep-base-command): Document format-string arguments.
Canonicalize default grep arguments.
(counsel-grep): Make more flexible and efficient use of
counsel-grep-base-command by using it as a format string instead of
parsing it.
---
counsel.el | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/counsel.el b/counsel.el
index b62ddc0..ddfd12b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2274,10 +2274,11 @@ RG-PROMPT, if non-nil, is passed as `ivy-read' prompt
argument."
"rg -i --no-heading --line-number --color never -- %s ."))
;;** `counsel-grep'
-(defcustom counsel-grep-base-command "grep -nE -- %s %s"
- "Format string to use in `cousel-grep-function' to construct the command.
-
-Note: don't use single quotes for either the regex or the file name."
+(defcustom counsel-grep-base-command "grep -E -n -e %s %s"
+ "Format string used by `counsel-grep' to build a shell command.
+It should contain two %-sequences (see function `format') to be
+substituted by the search regexp and file, respectively. Neither
+%-sequence should be contained in single quotes."
:type 'string
:group 'ivy)
@@ -2349,11 +2350,9 @@ Note: don't use single quotes for either the regex or
the file name."
(counsel-require-program (car (split-string counsel-grep-base-command)))
(setq counsel-grep-last-line nil)
(setq counsel--git-dir default-directory)
- (if (string-match "%s$" counsel-grep-base-command)
- (setq counsel-grep-command
- (concat (substring counsel-grep-base-command 0 (match-beginning 0))
- (shell-quote-argument (buffer-file-name))))
- (error "expected `counsel-grep-base-command' to end in %%s"))
+ (setq counsel-grep-command
+ (format counsel-grep-base-command
+ "%s" (shell-quote-argument buffer-file-name)))
(let ((init-point (point))
res)
(unwind-protect