Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default string for grep-find in emacs

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 ?

like image 698
Zitrax Avatar asked Jan 27 '10 16:01

Zitrax


2 Answers

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 ")
like image 156
Trey Jackson Avatar answered Sep 28 '22 11:09

Trey Jackson


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")))
like image 31
sanityinc Avatar answered Sep 28 '22 10:09

sanityinc