Subject: Re: bug#32549: Allow passing custom options to vc-git-grep

From: Federico Tedin <[email-masked]>
Date: Sat, 1 Sep 2018 18:55:15 -0300

I'm attaching a patch with the implementation of the new feature
(vc-git-grep-template).
From 55243e6e72414ce35058be2ad45a8ca6643ed14a Mon Sep 17 00:00:00 2001
From: Federico Tedin <[email-masked]>
Date: Sat, 1 Sep 2018 18:46:16 -0300
Subject: [PATCH 1/1] Add variable vc-git-grep-template

* lisp/vc/vc-git.el (vc-git-grep-template): New variable, allows
  changing the default arguments passed to git-grep when using
  'vc-git-grep'.
* etc/NEWS: Mention 'vc-git-grep-template'.  (Bug#32549)
---
 etc/NEWS          |  4 ++++
 lisp/vc/vc-git.el | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 1fe662ffff..fa600c67b5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -277,6 +277,10 @@ still be used if it exists.)  Set the variable to nil to get the
 previous behavior of always creating a buffer that visits a ChangeLog
 file.
 
+*** New customizable variable 'vc-git-grep-template'.
+This new variable allows customizing the default arguments passed to
+git-grep when 'vc-git-grep' is used.
+
 ** diff-mode
 *** Hunks are now automatically refined by default.
 To disable it, set the new defcustom 'diff-font-lock-refine' to nil.
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 96c2f38af4..567f00104b 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -179,6 +179,14 @@ vc-git-log-output-coding-system
   :type '(coding-system :tag "Coding system to decode Git log output")
   :version "25.1")
 
+(defcustom vc-git-grep-template "git --no-pager grep -n -e <R> -- <F>"
+  "The default command to run for \\[vc-git-grep].
+The following place holders should be present in the string:
+ <F> - file names and wildcards to search.
+ <R> - the regular expression searched for."
+  :type 'string
+  :version "27.1")
+
 ;; History of Git commands.
 (defvar vc-git-history nil)
 
@@ -1449,7 +1457,7 @@ vc-git-grep
 	      (setq command nil))
 	(setq dir (file-name-as-directory (expand-file-name dir)))
 	(setq command
-	      (grep-expand-template "git --no-pager grep -n -e <R> -- <F>"
+	      (grep-expand-template vc-git-grep-template
                                     regexp files))
 	(when command
 	  (if (equal current-prefix-arg '(4))
-- 
2.17.1