8

我经常在 emacs 中使用命令 grep-find 来搜索我的源文件,但它总是在临时文件和备份文件等中找到匹配项。grep-find 的默认命令是:

find . -type f -print0 | xargs -0 -e grep -nH -e

我知道我可以在运行它之前对其进行修改以满足我的需要,但是如何更改它以使其在启动时正确?

4

4 回答 4

9

grep包预先计算了一堆默认值(但不一定在包加载时)。所以你会想要让它发生,然后重新定义 find 命令。就像是:

(grep-compute-defaults)
(setq grep-find-command "find . ! -name \"*~\" ! -name \"#*#\" -type f -print0 | xargs -0 -e grep -nH -e ")
于 2010-01-27T16:56:52.720 回答
8

如果您使用 lgrep 或 rgrep 而不是 grep-find,您可以提前设置忽略的文件/目录:

(eval-after-load "grep"
  '(progn
    (add-to-list 'grep-find-ignored-files "*.tmp")
    (add-to-list 'grep-find-ignored-directories "_darcs")))
于 2010-01-28T20:41:23.190 回答
2

If you use GNU grep another nice solution is to put something like this in your .bashrc

export GREP_OPTIONS="--exclude=*#* --exclude=*.svn* --exclude=entries --exclude=all-wcprops --exclude=*.xcuserstate --exclude=project.pbxproj --exclude=*.svn-base --exclude=*.tmp"

and just tell grep itself to ignore certain files. Then you get the same behavior from the command line too.

于 2011-06-08T21:35:48.427 回答
0

看看当前的 emacs 开发版本是如何处理它的——它提供了大量的排除模式。

于 2010-01-27T18:06:33.730 回答