aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Gutov2015-06-26 20:21:50 +0300
committerDmitry Gutov2015-06-27 23:57:28 +0300
commit9b4b4a8355506a0253d8a4943e0a9aa87f9e92eb (patch)
tree068efb98ea3c08db953b1989c26786254564cd50 /lisp
parentda5e0050ac161bd9d665c4b406a95bee4f3b4085 (diff)
downloademacs-9b4b4a8355506a0253d8a4943e0a9aa87f9e92eb.tar.gz
emacs-9b4b4a8355506a0253d8a4943e0a9aa87f9e92eb.zip
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'."
130(defcustom grep-template nil 130(defcustom grep-template nil
131 "The default command to run for \\[lgrep]. 131 "The default command to run for \\[lgrep].
132The following place holders should be present in the string: 132The following place holders should be present in the string:
133 <C> - place to put -i if case insensitive grep. 133 <C> - place to put the options like -i and --color.
134 <F> - file names and wildcards to search. 134 <F> - file names and wildcards to search.
135 <X> - file names and wildcards to exclude. 135 <X> - file names and wildcards to exclude.
136 <R> - the regular expression searched for. 136 <R> - the regular expression searched for.
@@ -177,7 +177,7 @@ The following place holders should be present in the string:
177 <D> - base directory for find 177 <D> - base directory for find
178 <X> - find options to restrict or expand the directory list 178 <X> - find options to restrict or expand the directory list
179 <F> - find options to limit the files matched 179 <F> - find options to limit the files matched
180 <C> - place to put -i if case insensitive grep 180 <C> - place to put the grep options like -i and --color
181 <R> - the regular expression searched for. 181 <R> - the regular expression searched for.
182In interactive usage, the actual value of this variable is set up 182In interactive usage, the actual value of this variable is set up
183by `grep-compute-defaults'; to change the default value, use 183by `grep-compute-defaults'; to change the default value, use
@@ -572,20 +572,22 @@ This function is called from `compilation-filter-hook'."
572 (unless (and grep-command grep-find-command 572 (unless (and grep-command grep-find-command
573 grep-template grep-find-template) 573 grep-template grep-find-template)
574 (let ((grep-options 574 (let ((grep-options
575 (concat (and grep-highlight-matches 575 (concat (if grep-use-null-device "-n" "-nH")
576 (grep-probe grep-program
577 `(nil nil nil "--color" "x" ,null-device)
578 nil 1)
579 (if (eq grep-highlight-matches 'always)
580 "--color=always " "--color "))
581 (if grep-use-null-device "-n" "-nH")
582 (if (grep-probe grep-program 576 (if (grep-probe grep-program
583 `(nil nil nil "-e" "foo" ,null-device) 577 `(nil nil nil "-e" "foo" ,null-device)
584 nil 1) 578 nil 1)
585 " -e")))) 579 " -e"))))
586 (unless grep-command 580 (unless grep-command
587 (setq grep-command 581 (setq grep-command
588 (format "%s %s " grep-program grep-options))) 582 (format "%s %s %s " grep-program grep-options
583 (or
584 (and grep-highlight-matches
585 (grep-probe grep-program
586 `(nil nil nil "--color" "x" ,null-device)
587 nil 1)
588 (if (eq grep-highlight-matches 'always)
589 "--color=always" "--color"))
590 ""))))
589 (unless grep-template 591 (unless grep-template
590 (setq grep-template 592 (setq grep-template
591 (format "%s <X> <C> %s <R> <F>" grep-program grep-options))) 593 (format "%s <X> <C> %s <R> <F>" grep-program grep-options)))
@@ -791,7 +793,7 @@ easily repeat a find command."
791;; User-friendly interactive API. 793;; User-friendly interactive API.
792 794
793(defconst grep-expand-keywords 795(defconst grep-expand-keywords
794 '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i")) 796 '(("<C>" . (mapconcat #'identity opts " "))
795 ("<D>" . (or dir ".")) 797 ("<D>" . (or dir "."))
796 ("<F>" . files) 798 ("<F>" . files)
797 ("<N>" . null-device) 799 ("<N>" . null-device)
@@ -804,7 +806,16 @@ substitution string. Note dynamic scoping of variables.")
804(defun grep-expand-template (template &optional regexp files dir excl) 806(defun grep-expand-template (template &optional regexp files dir excl)
805 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>." 807 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
806 (let* ((command template) 808 (let* ((command template)
807 (env `((cf . ,case-fold-search) 809 (env `((opts . ,(let (opts)
810 (when (and case-fold-search
811 (isearch-no-upper-case-p regexp t))
812 (push "-i" opts))
813 (cond
814 ((eq grep-highlight-matches 'always)
815 (push "--color=always" opts))
816 ((eq grep-highlight-matches 'auto)
817 (push "--color" opts)))
818 opts))
808 (excl . ,excl) 819 (excl . ,excl)
809 (dir . ,dir) 820 (dir . ,dir)
810 (files . ,files) 821 (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."
749 (require 'semantic/fw) 749 (require 'semantic/fw)
750 (grep-compute-defaults) 750 (grep-compute-defaults)
751 (defvar grep-find-template) 751 (defvar grep-find-template)
752 (let* ((grep-find-template 752 (let* ((grep-find-template (replace-regexp-in-string "-e " "-E "
753 (replace-regexp-in-string 753 grep-find-template t t))
754 ;; Override the use ot '--color=always' on MS-Windows.
755 "--color=always" ""
756 (replace-regexp-in-string "-e " "-E "
757 grep-find-template t t)
758 t t))
759 (command (rgrep-default-command (xref--regexp-to-extended regexp) 754 (command (rgrep-default-command (xref--regexp-to-extended regexp)
760 "*.*" dir)) 755 "*.*" dir))
761 (orig-buffers (buffer-list)) 756 (orig-buffers (buffer-list))