I often use the command grep-find in emacs to search through my source files, but it's annying that it always finds matches in temporary files and backup files and so on. The default command for grep-find is:
find . -type f -print0 | xargs -0 -e grep -nH -e
I know I can modify it before I run it to match my needs but how do I change it such that it's correct on startup ?
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 ")
If you use lgrep or rgrep instead of grep-find, you can set up ignored files/dirs in advance:
(eval-after-load "grep"
'(progn
(add-to-list 'grep-find-ignored-files "*.tmp")
(add-to-list 'grep-find-ignored-directories "_darcs")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With