summaryrefslogtreecommitdiff
path: root/helm-grep.el
diff options
context:
space:
mode:
authorZhenya Roubinchtein <zhenya1007@gmail.com>2017-09-25 13:28:22 -0700
committerZhenya Roubinchtein <zhenya1007@gmail.com>2017-09-25 13:28:22 -0700
commit6409a137084088b5768c68c61d0ca34f1e4e4f8d (patch)
treed55797b95ba04026aa5ea635979a7f0f7c9cac62 /helm-grep.el
parent150b447993ec7bc3ec658a12ecab180460674f05 (diff)
Pull out the logic for pipe commands into a separate function.
Having a separate function allows the user to advise and/or re-define just that function if they let-bind `helm-grep-default-command' around a call to `helm-do-grep-1' and friends, but still want to have the "space-separated patterns pipe to grep" functionality. (In my case, I let-bound it to command that runs codesearch to make a quick-and-dirty Emacs interface for that command).
Diffstat (limited to 'helm-grep.el')
-rw-r--r--helm-grep.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/helm-grep.el b/helm-grep.el
index 2e7f8f48..6817c321 100644
--- a/helm-grep.el
+++ b/helm-grep.el
@@ -420,6 +420,18 @@ It is intended to use as a let-bound variable, DON'T set this globaly.")
(or (and norm-com norm-com-ack-p)
(and rec-com rec-com-ack-p)))))))
+(defun helm-grep--pipe-command-for-grep-command (&optional grep-command)
+ (pcase (or grep-command (helm-grep-command))
+ ;; Use grep for GNU regexp based tools.
+ ((or "grep" "zgrep" "git-grep")
+ (format "grep --color=always%s %s"
+ (if smartcase " -i" "")
+ pipe-switches))
+ ;; Use ack-grep for PCRE based tools.
+ ;; Sometimes ack-grep cmd is ack only.
+ ((and (pred (string-match-p "ack")) ack)
+ (format "%s --smart-case --color %s" ack pipe-switches))))
+
(defun helm-grep--prepare-cmd-line (only-files &optional include zgrep)
(let* ((default-directory (or helm-ff-default-directory
(helm-default-directory)
@@ -463,16 +475,7 @@ It is intended to use as a let-bound variable, DON'T set this globaly.")
(pipe-switches (mapconcat 'identity helm-grep-pipe-cmd-switches " "))
(pipes
(helm-aif (cdr patterns)
- (cl-loop with pipcom = (pcase (helm-grep-command)
- ;; Use grep for GNU regexp based tools.
- ((or "grep" "zgrep" "git-grep")
- (format "grep --color=always%s %s"
- (if smartcase " -i" "")
- pipe-switches))
- ;; Use ack-grep for PCRE based tools.
- ;; Sometimes ack-grep cmd is ack only.
- ((and (pred (string-match-p "ack")) ack)
- (format "%s --smart-case --color %s" ack pipe-switches)))
+ (cl-loop with pipcom = (helm-grep--pipe-command-for-grep-command)
for p in it concat
(format " | %s %s" pipcom (shell-quote-argument p)))
"")))