From 6409a137084088b5768c68c61d0ca34f1e4e4f8d Mon Sep 17 00:00:00 2001 From: Zhenya Roubinchtein Date: Mon, 25 Sep 2017 13:28:22 -0700 Subject: 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). --- helm-grep.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'helm-grep.el') 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))) ""))) -- cgit v1.2.3