繁体   English   中英

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

[英]Change the default find-grep command in emacs

当我在emacs中执行find-grep命令时,我find . -type f -exec grep -nH -e {} + find . -type f -exec grep -nH -e {} + ,因为我使用fish shell作为默认shell,为了使这个命令工作,我必须执行find . -type f -exec grep -nH -e \\{\\} + 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 {} + find . -type f -exec grep -nH -e {} + 任何人都可以告诉我我在哪里做错了或我该怎么弄清楚这个?

您更改的文本看起来不像可执行代码。 可能你刚刚更改了一个doc字符串(实际上,一些谷歌搜索显示这是在grep-find-use-xargs的文档字符串中)。 但是Emacs非常可定制; 你所要做的就是将grep-find-template的值设置为更适合你个人的东西,你自己的.emacs/init.el或类似的东西。

(setq grep-find-template
      "find . <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

您需要使用函数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)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM