* How best to set grep command based on current directory?
@ 2022-04-09 1:10 Michael Welsh Duggan
2022-04-09 6:10 ` Eli Zaretskii
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Michael Welsh Duggan @ 2022-04-09 1:10 UTC (permalink / raw)
To: emacs-devel
I would like to change the program invocation in "M-x grep" (or maybe
"M-x grep-find") to default to "git grep" when in directories that are
in git trees. I could hack away at the grep.el sources to do this, or I
could write some advice around the grep command to do this, but I want
to ask here, first, if anyone believes that there is a more principled
way to make this change.
--
Michael Welsh Duggan
(md5i@md5i.com)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How best to set grep command based on current directory?
2022-04-09 1:10 How best to set grep command based on current directory? Michael Welsh Duggan
@ 2022-04-09 6:10 ` Eli Zaretskii
2022-04-09 9:22 ` Yuri Khan
2022-04-09 22:43 ` Jim Porter
2 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-04-09 6:10 UTC (permalink / raw)
To: Michael Welsh Duggan; +Cc: emacs-devel
> From: Michael Welsh Duggan <mwd@md5i.com>
> Date: Fri, 08 Apr 2022 21:10:19 -0400
>
> I would like to change the program invocation in "M-x grep" (or maybe
> "M-x grep-find") to default to "git grep" when in directories that are
> in git trees. I could hack away at the grep.el sources to do this, or I
> could write some advice around the grep command to do this, but I want
> to ask here, first, if anyone believes that there is a more principled
> way to make this change.
That must be an opt-in behavior, to avoid surprising the users.
"M-x grep" is a very old command, so I don't think we can change
its behavior in such radical ways unconditionally.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How best to set grep command based on current directory?
2022-04-09 1:10 How best to set grep command based on current directory? Michael Welsh Duggan
2022-04-09 6:10 ` Eli Zaretskii
@ 2022-04-09 9:22 ` Yuri Khan
2022-04-09 22:43 ` Jim Porter
2 siblings, 0 replies; 4+ messages in thread
From: Yuri Khan @ 2022-04-09 9:22 UTC (permalink / raw)
To: Michael Welsh Duggan; +Cc: Emacs developers
On Sat, 9 Apr 2022 at 08:11, Michael Welsh Duggan <mwd@md5i.com> wrote:
> I would like to change the program invocation in "M-x grep" (or maybe
> "M-x grep-find") to default to "git grep" when in directories that are
> in git trees. I could hack away at the grep.el sources to do this, or I
> could write some advice around the grep command to do this, but I want
> to ask here, first, if anyone believes that there is a more principled
> way to make this change.
I customize grep-command to "git --no-pager grep -nH -E -e ". When not
inside a git repository, or if I want to search untracked files, I
manually add --no-index.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: How best to set grep command based on current directory?
2022-04-09 1:10 How best to set grep command based on current directory? Michael Welsh Duggan
2022-04-09 6:10 ` Eli Zaretskii
2022-04-09 9:22 ` Yuri Khan
@ 2022-04-09 22:43 ` Jim Porter
2 siblings, 0 replies; 4+ messages in thread
From: Jim Porter @ 2022-04-09 22:43 UTC (permalink / raw)
To: Michael Welsh Duggan, emacs-devel
On 4/8/2022 6:10 PM, Michael Welsh Duggan wrote:
> I would like to change the program invocation in "M-x grep" (or maybe
> "M-x grep-find") to default to "git grep" when in directories that are
> in git trees. I could hack away at the grep.el sources to do this, or I
> could write some advice around the grep command to do this, but I want
> to ask here, first, if anyone believes that there is a more principled
> way to make this change.
If *recursive* grep is ok (as opposed to `M-x grep'), that's what I
wrote urgrep[1] to do. It's aware of Git directories as well as remote
Tramp hosts that may have a different set of commands available for use.
I've seen using it for a while and I think I've worked out most of the
bugs. (I haven't submitted it for inclusion in GNU ELPA yet since I'm
still debating on what to do with a few parts, especially the API.)
If not, maybe the code will at least give you some ideas. After a fair
bit of experimentation, I found that the following command produces the
most consistent rgrep-like results for both Git and non-Git directories:
git grep --no-index --exclude-standard
Even within Git repos, I found the above to work best, since it searches
untracked files (excluding .gitignored files) and recurses into
submodules. The fact that it also works well for non-Git directories is
a nice bonus too.
- Jim
[1] https://github.com/jimporter/urgrep
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-09 22:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-09 1:10 How best to set grep command based on current directory? Michael Welsh Duggan
2022-04-09 6:10 ` Eli Zaretskii
2022-04-09 9:22 ` Yuri Khan
2022-04-09 22:43 ` Jim Porter
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.