更改 emacs 中的默认 find-grep 命令
Change the default find-grep command in emacs
当我在 emacs 中执行 find-grep
命令时,我得到了 find . -type f -exec grep -nH -e {} +
,因为我使用 fish shell 作为默认 shell,使这个命令起作用我必须执行 find . -type f -exec grep -nH -e \{\} +
.
我试图修改 emacs 源代码,以下是我的更改:
/usr/share/emacs/24.4/lisp/ldefs-boot.el
第 12669 行:If `exec-plus' use `find -exec \{\} +'.
/usr/share/emacs/24.4/lisp/loaddefs.el
第 12669 行:If `exec-plus' use `find -exec \{\} +'.
但是没有任何意义,当我执行find-grep
时仍然显示find . -type f -exec grep -nH -e {} +
。谁能告诉我我哪里做错了或者我应该怎么解决这个问题?
您更改的文本看起来不像可执行代码。可能您刚刚更改了一个文档字符串(实际上,一些谷歌搜索显示这是在 grep-find-use-xargs
的文档字符串中)。但是 Emacs 是非常可定制的;您所要做的就是将 grep-find-template
的值设置为更适合您个人的值,在您自己的 .emacs/init.el
或类似的
中。
(setq grep-find-template
"find <D> <X> -type f <F> -exec grep <C> -nH -e <R> \{\} +")
请参阅 the manual 了解更多文档,当然还有内置文档 (ctrl-h v grep-find-template
RET).
实际的源代码在 http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/grep.el#n174 但你真的,真的,真的 不想编辑源代码。无需更改代码的用户级可定制性是 Emacs 的基础设计之一。学习使用这个工具。
您需要使用函数grep-apply-setting
来设置变量grep-find-command
,并在大括号前的反斜杠处加倍:
(grep-apply-setting 'grep-find-command "find . -type f -exec grep -nH -e \{\} +")
(grep-apply-setting 'grep-find-command '("find . -type f -exec grep -nH -e \{\} +" . 34))
将光标放在 -e
之后
如果你想保留原始值,你可以这样做。它会找到不超过两个目录级别的文件,这些文件不是 emacs 备份文件,并且在过去一周内被修改过。
(defun grep-find-newer-shallow ()
(interactive)
(let ((gfc grep-find-command))
(grep-apply-setting 'grep-find-command '("find . -maxdepth 2 -type f ! -name '*#' -mtime -7 -exec grep -nH -e \{\} +" . 69))
(call-interactively 'grep-find)
(grep-apply-setting 'grep-find-command gfc)))
当我在 emacs 中执行 find-grep
命令时,我得到了 find . -type f -exec grep -nH -e {} +
,因为我使用 fish shell 作为默认 shell,使这个命令起作用我必须执行 find . -type f -exec grep -nH -e \{\} +
.
我试图修改 emacs 源代码,以下是我的更改:
/usr/share/emacs/24.4/lisp/ldefs-boot.el
第 12669 行:If `exec-plus' use `find -exec \{\} +'.
/usr/share/emacs/24.4/lisp/loaddefs.el
第 12669 行:If `exec-plus' use `find -exec \{\} +'.
但是没有任何意义,当我执行find-grep
时仍然显示find . -type f -exec grep -nH -e {} +
。谁能告诉我我哪里做错了或者我应该怎么解决这个问题?
您更改的文本看起来不像可执行代码。可能您刚刚更改了一个文档字符串(实际上,一些谷歌搜索显示这是在 grep-find-use-xargs
的文档字符串中)。但是 Emacs 是非常可定制的;您所要做的就是将 grep-find-template
的值设置为更适合您个人的值,在您自己的 .emacs/init.el
或类似的
(setq grep-find-template
"find <D> <X> -type f <F> -exec grep <C> -nH -e <R> \{\} +")
请参阅 the manual 了解更多文档,当然还有内置文档 (ctrl-h v grep-find-template
RET).
实际的源代码在 http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/grep.el#n174 但你真的,真的,真的 不想编辑源代码。无需更改代码的用户级可定制性是 Emacs 的基础设计之一。学习使用这个工具。
您需要使用函数grep-apply-setting
来设置变量grep-find-command
,并在大括号前的反斜杠处加倍:
(grep-apply-setting 'grep-find-command "find . -type f -exec grep -nH -e \{\} +")
(grep-apply-setting 'grep-find-command '("find . -type f -exec grep -nH -e \{\} +" . 34))
将光标放在 -e
如果你想保留原始值,你可以这样做。它会找到不超过两个目录级别的文件,这些文件不是 emacs 备份文件,并且在过去一周内被修改过。
(defun grep-find-newer-shallow ()
(interactive)
(let ((gfc grep-find-command))
(grep-apply-setting 'grep-find-command '("find . -maxdepth 2 -type f ! -name '*#' -mtime -7 -exec grep -nH -e \{\} +" . 69))
(call-interactively 'grep-find)
(grep-apply-setting 'grep-find-command gfc)))