unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32549: Allow passing custom options to vc-git-grep
@ 2018-08-27 23:03 Federico Tedin
  2018-08-27 23:20 ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Federico Tedin @ 2018-08-27 23:03 UTC (permalink / raw)
  To: 32549

When using vc-git-grep, it is not possible to pass custom options to
the git grep command. It would be good to have a customizable template
variable for vc-git-grep (like grep-command or grep-find-command) to
allow for more customization. I am willing to implement this feature
assuming there's no other possible workaround.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-27 23:03 bug#32549: Allow passing custom options to vc-git-grep Federico Tedin
@ 2018-08-27 23:20 ` Noam Postavsky
  2018-08-28  2:55   ` Federico Tedin
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-08-27 23:20 UTC (permalink / raw)
  To: Federico Tedin; +Cc: 32549

Federico Tedin <federicotedin@gmail.com> writes:

> When using vc-git-grep, it is not possible to pass custom options to
> the git grep command. It would be good to have a customizable template
> variable for vc-git-grep (like grep-command or grep-find-command) to
> allow for more customization. I am willing to implement this feature
> assuming there's no other possible workaround.

Does C-u help?  From the docstring:

    With C-u prefix, you can edit the constructed shell command line
    before it is executed.
    With two C-u prefixes, directly edit and run ‘grep-command’.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-27 23:20 ` Noam Postavsky
@ 2018-08-28  2:55   ` Federico Tedin
  2018-08-28  3:52     ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Federico Tedin @ 2018-08-28  2:55 UTC (permalink / raw)
  To: 32549

> Does C-u help?  From the docstring:
>
>     With C-u prefix, you can edit the constructed shell command line
>     before it is executed.
>     With two C-u prefixes, directly edit and run ‘grep-command’.

You're right! With C-u, I am eventually prompted for the full git-grep
arguments, This is useful
when manually invoking the command, but now I'm wondering how I would
set my custom arguments
when the vc-git-grep function is called from another function. For
example, the projectile package
defines projectile-grep, which eventually calls rgrep or vc-git-grep
[1] (depending on the user's choice).

[1] https://github.com/bbatsov/projectile/blob/master/projectile.el#L2757





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-28  2:55   ` Federico Tedin
@ 2018-08-28  3:52     ` Noam Postavsky
  2018-08-28 23:01       ` Federico Tedin
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-08-28  3:52 UTC (permalink / raw)
  To: Federico Tedin; +Cc: 32549

Federico Tedin <federicotedin@gmail.com> writes:

> I'm wondering how I would set my custom arguments when the vc-git-grep
> function is called from another function. For example, the projectile
> package defines projectile-grep, which eventually calls rgrep or
> vc-git-grep [1] (depending on the user's choice).

It looks like you'd have to do

    (let ((current-prefix-arg '(4)))
      (vc-git-grep ...))





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-28  3:52     ` Noam Postavsky
@ 2018-08-28 23:01       ` Federico Tedin
  2018-08-28 23:14         ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Federico Tedin @ 2018-08-28 23:01 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 32549

> > I'm wondering how I would set my custom arguments when the vc-git-grep
> > function is called from another function. For example, the projectile
> > package defines projectile-grep, which eventually calls rgrep or
> > vc-git-grep [1] (depending on the user's choice).
>
> It looks like you'd have to do
>
>     (let ((current-prefix-arg '(4)))
>       (vc-git-grep ...))

I've set the prefix argument using the current-prefix-arg variable as
you mentioned:

(let ((current-prefix-arg '(4)))
  (vc-git-grep "something" "*.el" "."))

And then I also tried:

(let ((current-prefix-arg '(4)))
  (projectile-grep))

In both cases, I am prompted for the full git-grep command (and nothing else).
Is there any way to set a default set of arguments in order to avoid typing them
when invoking the function?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-28 23:01       ` Federico Tedin
@ 2018-08-28 23:14         ` Noam Postavsky
  2018-08-28 23:31           ` Federico Tedin
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-08-28 23:14 UTC (permalink / raw)
  To: Federico Tedin; +Cc: 32549

Federico Tedin <federicotedin@gmail.com> writes:

> (let ((current-prefix-arg '(4)))
>   (vc-git-grep "something" "*.el" "."))
>
> And then I also tried:
>
> (let ((current-prefix-arg '(4)))
>   (projectile-grep))
>
> In both cases, I am prompted for the full git-grep command (and
> nothing else).

Doesn't projectile-grep prompt you for a regexp?  I don't have it
installed here, but it looks like you have to pass a non-nil ARG to get
prompted for filenames, i.e.,

  (let ((current-prefix-arg '(4)))
    (projectile-grep nil t))

> Is there any way to set a default set of arguments in order to avoid
> typing them when invoking the function?

Not sure I follow, when you pass "something" and "*.el" to the function,
those get inserted into the default command so you don't have to type
them interactively.






^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-28 23:14         ` Noam Postavsky
@ 2018-08-28 23:31           ` Federico Tedin
  2018-08-29  0:45             ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Federico Tedin @ 2018-08-28 23:31 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 32549

> Doesn't projectile-grep prompt you for a regexp?  I don't have it
> installed here, but it looks like you have to pass a non-nil ARG to get
> prompted for filenames, i.e.,
>
>   (let ((current-prefix-arg '(4)))
>     (projectile-grep nil t))

My mistake. Calling projectile-grep with current-prefix-arg '(4) indeed prompts
for the git-grep command _and_ a regexp.

> > Is there any way to set a default set of arguments in order to avoid
> > typing them when invoking the function?
>
> Not sure I follow, when you pass "something" and "*.el" to the function,
> those get inserted into the default command so you don't have to type
> them interactively.

I am sorry if I wasn't clear enough. What I'm trying to say is, when calling
vc-git-grep directly or indirectly with current-prefix-arg '(4), I am always
prompted for the full git-grep command. I would like to skip this step
completely,
and always use a custom set of arguments (like, for example, "-C 3"). Then, I
would be prompted for a regexp and (maybe) files, which would be added to this
custom git-grep command's arguments (this is how the rgrep command works, I
think).





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-28 23:31           ` Federico Tedin
@ 2018-08-29  0:45             ` Noam Postavsky
  2018-08-29  0:54               ` Federico Tedin
  0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-08-29  0:45 UTC (permalink / raw)
  To: Federico Tedin; +Cc: 32549

Federico Tedin <federicotedin@gmail.com> writes:

> when calling vc-git-grep directly or indirectly with
> current-prefix-arg '(4), I am always prompted for the full git-grep
> command. I would like to skip this step completely,
> and always use a custom set of arguments (like, for example, "-C 3"). Then, I
> would be prompted for a regexp and (maybe) files, which would be added to this
> custom git-grep command's arguments (this is how the rgrep command works, I
> think).

Ah, I see what you mean, vc-git-grep hardcodes the grep-command
template, so it doesn't allow for this.  Would you like to send a patch?






^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-29  0:45             ` Noam Postavsky
@ 2018-08-29  0:54               ` Federico Tedin
  2018-09-01 21:55                 ` Federico Tedin
  0 siblings, 1 reply; 11+ messages in thread
From: Federico Tedin @ 2018-08-29  0:54 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 32549

> Ah, I see what you mean, vc-git-grep hardcodes the grep-command
> template, so it doesn't allow for this.  Would you like to send a patch?

Sure! I'll start working on it.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-08-29  0:54               ` Federico Tedin
@ 2018-09-01 21:55                 ` Federico Tedin
  2018-09-04 23:03                   ` Noam Postavsky
  0 siblings, 1 reply; 11+ messages in thread
From: Federico Tedin @ 2018-09-01 21:55 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 32549

[-- Attachment #1: Type: text/plain, Size: 89 bytes --]

I'm attaching a patch with the implementation of the new feature
(vc-git-grep-template).

[-- Attachment #2: 0001-Add-variable-vc-git-grep-template.patch --]
[-- Type: text/x-diff, Size: 2135 bytes --]

From 55243e6e72414ce35058be2ad45a8ca6643ed14a Mon Sep 17 00:00:00 2001
From: Federico Tedin <federicotedin@gmail.com>
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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#32549: Allow passing custom options to vc-git-grep
  2018-09-01 21:55                 ` Federico Tedin
@ 2018-09-04 23:03                   ` Noam Postavsky
  0 siblings, 0 replies; 11+ messages in thread
From: Noam Postavsky @ 2018-09-04 23:03 UTC (permalink / raw)
  To: Federico Tedin; +Cc: 32549

tags 32549 fixed
close 32549 27.1
quit

Federico Tedin <federicotedin@gmail.com> writes:

> I'm attaching a patch with the implementation of the new feature
> (vc-git-grep-template).

Thanks, pushed to master.

[1: e3661f8c35]: 2018-09-04 18:53:59 -0400
  Add variable vc-git-grep-template
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=e3661f8c35b3057c58e8c0b474f597697ce413ba





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-09-04 23:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-27 23:03 bug#32549: Allow passing custom options to vc-git-grep Federico Tedin
2018-08-27 23:20 ` Noam Postavsky
2018-08-28  2:55   ` Federico Tedin
2018-08-28  3:52     ` Noam Postavsky
2018-08-28 23:01       ` Federico Tedin
2018-08-28 23:14         ` Noam Postavsky
2018-08-28 23:31           ` Federico Tedin
2018-08-29  0:45             ` Noam Postavsky
2018-08-29  0:54               ` Federico Tedin
2018-09-01 21:55                 ` Federico Tedin
2018-09-04 23:03                   ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).