branch: master
commit 0312d5e1cc1784d9b196bc862a90d151fc8d80a9
Author: Yevgnen Koh <[email protected]>
Commit: Yevgnen Koh <[email protected]>
Make counsel-ag support limiting in files.
This is be done by detecting " -- " in extra-ag-args after
prompting, since ag supports " -- pattern file1 file2" style
of searching.
---
counsel.el | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/counsel.el b/counsel.el
index a40d29d..33e6c1a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1682,10 +1682,18 @@ If non-nil, EXTRA-AG-ARGS string is appended to
BASE-CMD."
(regex (counsel-unquote-regex-parens
(setq ivy--old-re
(ivy--regex string)))))
- (let ((ag-cmd (format base-cmd
- (concat extra-ag-args
- " -- "
- (shell-quote-argument regex)))))
+ (let* ((args-end (string-match " -- " extra-ag-args))
+ (file (if args-end
+ (substring-no-properties extra-ag-args (+ args-end 3))
+ ""))
+ (extra-ag-args (if args-end
+ (substring-no-properties extra-ag-args 0
args-end)
+ extra-ag-args))
+ (ag-cmd (format counsel-ag-base-command
+ (concat extra-ag-args
+ " -- "
+ (shell-quote-argument regex)
+ file))))
(if (file-remote-p default-directory)
(split-string (shell-command-to-string ag-cmd) "\n" t)
(counsel--async-command ag-cmd)