更改emacs中默认的查找命令find-grep

6
当我在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行:如果使用“exec-plus”,请使用“find -exec \{\} +”。 /usr/share/emacs/24.4/lisp/loaddefs.el第12669行:如果使用“exec-plus”,请使用“find -exec \{\} +”。
但这没有任何意义,当我执行find-grep时仍然显示find . -type f -exec grep -nH -e {} +。有人能告诉我我做错了什么或者我该如何解决这个问题吗?
4个回答

5
(grep-apply-setting 'grep-find-command '("find . -type f -exec grep -nH -e  \\{\\} +" . 34))

会将光标放在-e后面一点的位置。

5
你更改的文本看起来不像可执行代码。可能只是更改了一个文档字符串(实际上,一些搜索显示这是grep-find-use-xargs的文档字符串)。但是Emacs是非常可定制的;你只需要在自己的.emacs/init.el或类似位置中设置grep-find-template的值,以适合你个人更多。请保留HTML标签。
(setq grep-find-template
      "find <D> <X> -type f <F> -exec grep <C> -nH -e <R> \\{\\} +")

请参阅手册获取更多文档,当然还有内置文档(ctrl-h v grep-find-template RET)。
实际源代码位于http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/grep.el#n174,但您真的、真的不想编辑源代码。在Emacs中,无需更改代码即可进行用户级自定义是基础设计之一。学会使用此功能。

我在emacs的源目录中搜索了grep-find,并找到这两个文件匹配,所以我尝试修改它们。你的回答帮了很大的忙,我在/usr/share/emacs/24.4/lisp/progmodes/grep.el.gz中找到了grep-find的定义。 - Joey
2
不要修改文件。只需在您自己的个人init文件中覆盖需要覆盖的内容即可。对源代码的任何更改都将在下次升级时丢失,并且在多用户系统上,您会破坏其他所有人的东西。 - tripleee
1
我会使用 <D>,而不是 .grep-find-template 的文档字符串说应该使用所有的占位符。例如,我的是:"find -L <D> <X> -type f <F> -exec grep <C> -nH -e <R> \\{\\} +" - sam boosalis

4

您需要使用函数grep-apply-setting来设置变量grep-find-command,并在花括号之前加倍反斜杠:

(grep-apply-setting 'grep-find-command "find . -type f -exec grep -nH -e  \\{\\} +")

我可以将默认光标位置设置为“-e(此处)\{\}”吗? - Daishi Nakajima

1
如果您想保留原始值,可以这样做。它将查找不超过两个目录级别的文件,不是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)))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接