Skip to content

Commit

Permalink
Fix issue #1618 for ag as well.
Browse files Browse the repository at this point in the history
* helm-grep.el (helm-grep--prepare-cmd-line): Ensure end space is removed when needed.
(helm-grep-ag-prepare-cmd-line): Do it, use --smart-case.
  • Loading branch information
Thierry Volpiatto committed Oct 15, 2016
1 parent 894b69e commit 9867cf6
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions helm-grep.el
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,12 @@ It is intended to use as a let-bound variable, DON'T set this globaly.")
;; we need to pass an empty string
;; to types to avoid error.
(or include "")))
(smartcase (if (helm-grep-use-ack-p) ""
(unless (let ((case-fold-search nil))
(string-match-p
"[[:upper:]]" helm-pattern)) "i")))
(smartcase (if (helm-grep-use-ack-p)
""
(unless (let ((case-fold-search nil))
(string-match-p
"[[:upper:]]" helm-pattern))
"i")))
(helm-grep-default-command
(concat helm-grep-default-command " %m")) ; `%m' like multi.
(patterns (split-string helm-pattern))
Expand All @@ -429,8 +431,10 @@ It is intended to use as a let-bound variable, DON'T set this globaly.")
(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"
(if smartcase "-i" "")))
(replace-regexp-in-string
"\\s-\\'" ""
(format "grep --color=always %s"
(if smartcase "-i" ""))))
;; Use ack-grep for PCRE based tools.
;; Sometimes ack-grep cmd is ack only.
((and (pred (string-match-p "ack")) ack)
Expand Down Expand Up @@ -1321,9 +1325,14 @@ Ripgrep (rg) types are also supported if this backend is used."
When TYPE is specified it is one of what returns `helm-grep-ag-get-types'
if available with current AG version."
(let* ((patterns (split-string pattern))
(pipe-cmd (cond ((executable-find "ack") "ack --color")
((executable-find "ack-grep") "ack-grep --color")
(t "grep --perl-regexp --color=always")))
(smartcase (let ((case-fold-search nil))
(string-match-p
"[[:upper:]]" helm-pattern)))
(pipe-cmd (cond ((executable-find "ack") "ack --smart-case --color")
((executable-find "ack-grep") "ack-grep --smart-case --color")
(t (replace-regexp-in-string
"\\s-\\'" "" (format "grep --perl-regexp --color=always %s"
(if smartcase "-i" ""))))))
(cmd (format helm-grep-ag-command
(mapconcat 'identity type " ")
(shell-quote-argument (car patterns))
Expand Down

0 comments on commit 9867cf6

Please sign in to comment.