Change The Default Find-Grep Command in Emacs

Change the default find-grep command in emacs

The text you changed does not look like executable code. Probably you just changed a doc string (actually, a bit of googling reveals that this is in the documentation string for grep-find-use-xargs). But Emacs is eminently customizable; all you have to do is to set the value of grep-find-template to something which is more suitable for you personally, in your own .emacs/init.el or similar.

(setq grep-find-template
"find <D> <X> -type f <F> -exec grep <C> -nH -e <R> \\{\\} +")

See the manual for further documentation and, of course, the built-in documentation (ctrl-h v grep-find-template RET).

The actual source code is in http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/grep.el#n174 but you really, really, really do not want to edit the source code. The user-level customizability without code changes is one of the foundational designs of Emacs. Learn to use this facility.

Change the default cursor position of find-grep command in emacs

Change the code in your init.el to the following:

(grep-apply-setting 'grep-find-command '("find . -type d \\( -name '.git' \\) -prune -o -type f  -exec grep -nH -e  \\{\\} +" . 72))

Default string for grep-find in emacs

The grep package computes a bunch of defaults up front (but not necessarily on package load). So you'll want to get that to happen, and then redefine the find command. Something like:

(grep-compute-defaults)
(setq grep-find-command "find . ! -name \"*~\" ! -name \"#*#\" -type f -print0 | xargs -0 -e grep -nH -e ")

EMACS find-grep command switching windows

See the functions next-error and previous-error. They leave the grep buffer, but they work from anywhere, so, for example, if you bind next-error to a convenient a key then you can keep pressing it and it will iterate over the grep buffer.

How to get emacs grep to search based on project root?

This does not answer directly your grep question but especially when working with projects, I always find projectile to be a great tool.

Projectile, amongst other things, provides a grep, ack and ag search on a project level which is probably what you are looking for.

E.g.

C-c p s g runs grep on the files in the project.



Related Topics



Leave a reply



Submit