summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2015-06-26 20:21:50 +0300
committerDmitry Gutov <dgutov@yandex.ru>2015-06-27 23:57:28 +0300
commit9b4b4a8355506a0253d8a4943e0a9aa87f9e92eb (patch)
tree068efb98ea3c08db953b1989c26786254564cd50 /lisp
parentda5e0050ac161bd9d665c4b406a95bee4f3b4085 (diff)
downloademacs-9b4b4a8355506a0253d8a4943e0a9aa87f9e92eb.tar.gz
Add --color Grep option to the command dynamically
* lisp/progmodes/grep.el (grep-template, grep-find-template): Update the description for <C>. (Bug#20728) (grep-compute-defaults): Don't add the --color option to grep-options. Only add it to grep-command. (grep-expand-keywords): Expand the env value opts into <C>. (grep-expand-template): Replace cf in the env with the opts list, that can include -i and --color. * lisp/progmodes/xref.el (xref-collect-matches): Do not remove "--color=always" from the template, because we don't have to.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/grep.el35
-rw-r--r--lisp/progmodes/xref.el9
2 files changed, 25 insertions, 19 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index cc6662f3bf3..e20e5bd4c40 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -130,7 +130,7 @@ Customize or call the function `grep-apply-setting'."
(defcustom grep-template nil
"The default command to run for \\[lgrep].
The following place holders should be present in the string:
- <C> - place to put -i if case insensitive grep.
+ <C> - place to put the options like -i and --color.
<F> - file names and wildcards to search.
<X> - file names and wildcards to exclude.
<R> - the regular expression searched for.
@@ -177,7 +177,7 @@ The following place holders should be present in the string:
<D> - base directory for find
<X> - find options to restrict or expand the directory list
<F> - find options to limit the files matched
- <C> - place to put -i if case insensitive grep
+ <C> - place to put the grep options like -i and --color
<R> - the regular expression searched for.
In interactive usage, the actual value of this variable is set up
by `grep-compute-defaults'; to change the default value, use
@@ -572,20 +572,22 @@ This function is called from `compilation-filter-hook'."
(unless (and grep-command grep-find-command
grep-template grep-find-template)
(let ((grep-options
- (concat (and grep-highlight-matches
- (grep-probe grep-program
- `(nil nil nil "--color" "x" ,null-device)
- nil 1)
- (if (eq grep-highlight-matches 'always)
- "--color=always " "--color "))
- (if grep-use-null-device "-n" "-nH")
+ (concat (if grep-use-null-device "-n" "-nH")
(if (grep-probe grep-program
`(nil nil nil "-e" "foo" ,null-device)
nil 1)
" -e"))))
(unless grep-command
(setq grep-command
- (format "%s %s " grep-program grep-options)))
+ (format "%s %s %s " grep-program grep-options
+ (or
+ (and grep-highlight-matches
+ (grep-probe grep-program
+ `(nil nil nil "--color" "x" ,null-device)
+ nil 1)
+ (if (eq grep-highlight-matches 'always)
+ "--color=always" "--color"))
+ ""))))
(unless grep-template
(setq grep-template
(format "%s <X> <C> %s <R> <F>" grep-program grep-options)))
@@ -791,7 +793,7 @@ easily repeat a find command."
;; User-friendly interactive API.
(defconst grep-expand-keywords
- '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i"))
+ '(("<C>" . (mapconcat #'identity opts " "))
("<D>" . (or dir "."))
("<F>" . files)
("<N>" . null-device)
@@ -804,7 +806,16 @@ substitution string. Note dynamic scoping of variables.")
(defun grep-expand-template (template &optional regexp files dir excl)
"Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
(let* ((command template)
- (env `((cf . ,case-fold-search)
+ (env `((opts . ,(let (opts)
+ (when (and case-fold-search
+ (isearch-no-upper-case-p regexp t))
+ (push "-i" opts))
+ (cond
+ ((eq grep-highlight-matches 'always)
+ (push "--color=always" opts))
+ ((eq grep-highlight-matches 'auto)
+ (push "--color" opts)))
+ opts))
(excl . ,excl)
(dir . ,dir)
(files . ,files)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 469f65d4fa6..50d52d01efe 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -749,13 +749,8 @@ tools are used, and when."
(require 'semantic/fw)
(grep-compute-defaults)
(defvar grep-find-template)
- (let* ((grep-find-template
- (replace-regexp-in-string
- ;; Override the use ot '--color=always' on MS-Windows.
- "--color=always" ""
- (replace-regexp-in-string "-e " "-E "
- grep-find-template t t)
- t t))
+ (let* ((grep-find-template (replace-regexp-in-string "-e " "-E "
+ grep-find-template t t))
(command (rgrep-default-command (xref--regexp-to-extended regexp)
"*.*" dir))
(orig-buffers (buffer-list))