【问题标题】:Rgrep in Emacs to use ripgrepEmacs 中的 rgrep 使用 ripgrep
【发布时间】:2017-08-05 21:47:33
【问题描述】:

我们如何自定义 Emacs 的 rgrep 以使用 ripgrep(rg 可执行文件)——使其同时在拉丁语 1、UTF-8 和 UTF-16 中搜索?

想法是重用 Emacs 的标准 rgrep 命令,这样我们就可以同时使用 next-error 和 previous-error...

我不知道如何完全集成(对于基本目录)和(对于匹配的文件)说明符等。

(grep-apply-setting 'grep-find-template
                    "rg -uu -g <F> <R> <D>")

将产生(在 *.txt 文件中搜索时)

rg -uu -g \( -iname \*.txt \) test .
error: Invalid value for '--max-count <NUM>': invalid digit found in string

Grep exited abnormally with code 1 at Sun Aug  6 00:23:58

【问题讨论】:

  • rg 不支持 find 谓词。只是正常的通配符。您必须将其与find 命令结合使用。
  • @JürgenHötzel 感谢您提供信息。您能否展示一下如何编写它(并将其作为答案发布)?
  • melpa 中有两个包可以与 ripgrep 一起使用:rgripgrep。我现在正在试用rg,因为它说它支持wgrep-agwgrep 是我最喜欢的功能之一。

标签: utf-8 emacs grep utf-16 ripgrep


【解决方案1】:

grep-find-template 用于将grepcommand 与find 结合使用。这对我有用:

(grep-apply-setting 'grep-find-template "find <D> <X> -type f <F> -exec rg <C> --no-heading -H  <R> /dev/null {} +")

如果你想使用rg 而不使用find,你必须使用lgrep 并自定义:

(grep-apply-setting 'grep-template "rg --no-heading -H -uu -g <F> <R> <D>")

【讨论】:

  • 谢谢。对于 rg,grep-command 和 grep-find-command 应该设置什么?
  • 得到一个“搜索失败。这意味着某处有不匹配的表达式,或者我们在文件的开头/结尾。”测试 M-x rgrep 时。我不明白字符串末尾的 + 号。对吗?
  • +find 语法的一部分。它定义了exec 操作的结束。
  • 您的解决方案(不知道第一次发生了什么)或(grep-apply-setting 'grep-find-template "find &lt;D&gt; &lt;X&gt; -type f &lt;F&gt; -exec rg &lt;C&gt; --no-heading -H &lt;R&gt; /dev/null {} \\;") 几乎对我有用:消息/dev/null: The system cannot find the file specified. (os error 2) 显示在命令和结果之间(在*grep* 缓冲区中)。并且比赛不再以颜色显示。知道有什么问题吗?谢谢!
  • 事实上,关于/dev/null 的消息也会出现在结果之间——它是其中的一部分。不知为何……
猜你喜欢
  • 2010-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 2023-02-18
相关资源
最近更新 更多