views:

204

answers:

3

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 ?

+3  A: 

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 ")
Trey Jackson
Thanks this works fine (just needs a space at the end).
Zitrax
+1  A: 

Take a look at how the current development version of emacs handles it -- it supplies a huge list of exclusion patterns.

offby1
If the list is huge do they avoid listing the full command in the mini buffer ? I don't really need to see it each time I do a search.
Zitrax
a) try it and see;b) yes, they do avoid listing it in the minibuffer. It does, however, show up at the top of the `*grep*` buffer (i.e., where the output goes), and it's pretty huge.
offby1
+1  A: 

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")))
sanityinc