快速和肮脏的方式是前缀find-grep
,即C-u M-x find-grep
。它允许您在执行之前编辑命令行。
如果你想永久改变它,你可以定义一个包装器。这是为rgrep
,但find-grep
应该是相似的。
(defvar grep-context-lines 2
"Default number of context lines (non-matching lines before and
after the matching line) for `rgrep-context'.")
(defun rgrep-context (arg)
"Like `rgrep', but adds a '-C' parameter to get context lines around matches.
Default number of context lines is `grep-context-lines', and can
be specified with a numeric prefix."
(interactive "p")
(setq arg (or arg grep-context-lines))
(let ((grep-find-template
(format "find <D> <X> -type f <F> -print0 | xargs -0 -e grep <C> -nH -C %d -e <R>"
arg))
grep-host-defaults-alist
current-prefix-arg)
(call-interactively 'rgrep)))
感谢您的回复。 我该如何着手编写find-grep。说'java-find-grep',它包括一个额外的选项来查找命令('-iname'* .java'') – user462455
正如我所说的,复制'find-grep'的定义,将副本的命令名更改为'java-find-grep',并替换'find-grep'定义中使用的'find'命令。要查找'find-grep'的定义,请使用'C-h f find-grep RET'。 – Drew
'C-h f find-grep RET'给出了find-grep的描述,但我无法找到该函数的源代码。 – user462455