【问题标题】:Change the default find-grep command in emacs更改 emacs 中的默认 find-grep 命令
【发布时间】:2015-05-09 00:53:25
【问题描述】:

当我在 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 {} +。谁能告诉我我哪里做错了或者我应该如何解决这个问题?

【问题讨论】:

    标签: linux emacs fish


    【解决方案1】:

    您更改的文本看起来不像可执行代码。可能您只是更改了一个文档字符串(实际上,通过谷歌搜索发现这是在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 的基础设计之一。学习使用这个工具。

    【讨论】:

    • 我在 emacs 的源目录中搜索 grep-find 并发现这两个文件匹配,所以我尝试修改它们。你的回答很有帮助,我在/usr/share/emacs/24.4/lisp/progmodes/grep.el.gz找到了grep-find的定义@
    • 不,不要修改文件。只需在您自己的个人初始化文件中覆盖您需要覆盖的内容。对源的任何更改都将在下次升级时丢失,并且在多用户系统上,您正在破坏其他所有人的东西。
    • 我会使用&lt;D&gt;,而不是. _______ grep-find-template 的文档字符串说应该使用所有占位符。例如我的是:"find -L &lt;D&gt; &lt;X&gt; -type f &lt;F&gt; -exec grep &lt;C&gt; -nH -e &lt;R&gt; \\{\\} +".
    【解决方案2】:
    (grep-apply-setting 'grep-find-command '("find . -type f -exec grep -nH -e  \\{\\} +" . 34))
    

    将光标放在-e 的后面一点

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 我可以将默认光标位置设置为-e (here) \\{\\}吗?
      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多