快速和骯髒的方式是前綴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