emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 9b4b4a8: Add --color Grep option to the command dyn


From: Dmitry Gutov
Subject: [Emacs-diffs] master 9b4b4a8: Add --color Grep option to the command dynamically
Date: Sat, 27 Jun 2015 21:04:49 +0000

branch: master
commit 9b4b4a8355506a0253d8a4943e0a9aa87f9e92eb
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    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.
---
 etc/NEWS               |    9 +++++++++
 lisp/progmodes/grep.el |   35 +++++++++++++++++++++++------------
 lisp/progmodes/xref.el |    9 ++-------
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 8463655..1f8cbbc 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -883,6 +883,15 @@ word syntax, use `\sw' instead.
 ** The `diff' command uses the unified format now.  To restore the old
 behavior, set `diff-switches' to `-c'.
 
+** `grep-template' and `grep-find-template' values don't include the
+--color argument anymore.  It's added at the <C> place holder position
+dynamically.
+
+** `grep-template' and `grep-find-template' values don't include the
+--color argument anymore.  It's added at the <C> place holder position
+dynamically.  Any third-party code that changes these templates should
+be updated accordingly.
+
 
 * Lisp Changes in Emacs 25.1
 
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index cc6662f..e20e5bd 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 469f65d..50d52d0 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]