Emacs elisp编译,将regexp添加到错误检测

Emacs elisp编译,将regexp添加到错误检测,emacs,elisp,ack,compile-mode,Emacs,Elisp,Ack,Compile Mode,我从emacs开始,对elisp了解不多。几乎没什么,真的 我想用ack代替grep 以下是我在emacs中使用ack时遵循的说明: 现在我不喜欢这个el文件中使用的输出格式,我希望输出是ack--group 所以我改变了: (read-string "Ack arguments: " "-i" nil "-i" nil) 致: 到目前为止还不错。 但这使我无法在输出缓冲区的行上单击并按enter键。在最初的行为中,使用编译模式可以跳转到所选行 我想我应该在ack模式中添加一个regexp。

我从emacs开始,对elisp了解不多。几乎没什么,真的

我想用ack代替grep

以下是我在emacs中使用ack时遵循的说明:

现在我不喜欢这个el文件中使用的输出格式,我希望输出是
ack--group

所以我改变了:

(read-string "Ack arguments: " "-i" nil "-i" nil)
致:

到目前为止还不错。 但这使我无法在输出缓冲区的行上单击并按enter键。在最初的行为中,使用编译模式可以跳转到所选行

我想我应该在ack模式中添加一个regexp。确认模式定义如下:

(define-compilation-mode ack-mode "Ack"
  "Specialization of compilation-mode for use with ack."
   nil)
我想添加regexp
[0-9]+:
也被检测为错误,因为它是输出错误的每一行所包含的内容(行号)

我试图修改上面的
define编译模式
,以添加regexp,但失败惨重

如何制作
ack的输出缓冲区让我点击它的行

--编辑,我也试过:---

(defvar ack-regexp-alist 
    '(("[0-9]+:"
     2 3))
  "Alist that specifies how to match rows in ack output.")

(setq compilation-error-regexp-alist
      (append compilation-error-regexp-alist
          ack-regexp-alist))
我把它偷到某个地方,试着适应我的需要。不走运

——编辑,在Ivan的提议之后的结果---

(defvar ack-regexp-alist 
    '(("[0-9]+:"
     2 3))
  "Alist that specifies how to match rows in ack output.")

(setq compilation-error-regexp-alist
      (append compilation-error-regexp-alist
          ack-regexp-alist))
更新了ack.el,包括:

(defvar ack-regexp-alist 
  '(("^[0-9]+:" ;; match the line number
     nil        ;; the file is not found on this line, so assume that it's the same as before
     0          ;; The line is the 0'th subexpression (the whole thing)
     )
    ("^[^: ]+$" ;; match a file -- this could be better
     0          ;; The file is the 0'th subexpression
     ))
  "Alist that specifies how to match rows in ack output.")

(setq compilation-error-regexp-alist
      (append compilation-error-regexp-alist
          ack-regexp-alist))


(define-compilation-mode ack-mode "Ack"
  "Specialization of compilation-mode for use with ack."
   nil) 
然后检查
编译错误regext alist
变量,得到以下值:

(absoft ada aix ant bash borland caml comma edg-1 edg-2 epc ftnchek iar ibm irix java jikes-file jikes-line gnu gcc-include lcc makepp mips-1 mips-2 msft oracle perl rxp sparc-pascal-file sparc-pascal-line sparc-pascal-example sun sun-ada 4bsd gcov-file gcov-header gcov-nomark gcov-called-line gcov-never-called
        ("^[0-9]+:" nil 0)
        ("^[^: ]+$" 0))
我发现变量的格式很奇怪,不是吗?我还不认识elisp,所以这样可能是对的


*确认*缓冲区中仍然没有链接或颜色。

还有另一个
完整确认
包,我以前在它上面使用过,并处理
--组
输出

也就是说,阅读
编译错误regexp alist
的文档,您会发现它的形式如下:

(REGEXP FILE [LINE COLUMN TYPE HYPERLINK HIGHLIGHT...])
--group
输出的情况下,您必须分别匹配文件和行,因此我认为您需要类似(未测试)的内容

--更新--

变量
编译错误regext alist
是一个符号或元素列表,如
(REGEXP…
)。在
编译错误regexp>中查找符号,以找到相应的元素。是的,这有点奇怪,但更容易看到什么被打开和关闭,而不必看丑陋的正则表达式并猜测它们做什么。如果要分发此文件,我建议将正则表达式添加到编译错误regexp alist
中,然后在编译错误regext alist
中打开它,但在它正常工作之前,这有点毫无意义

仔细观察ack.el,我注意到它使用

(let (compile-command
      (compilation-error-regexp-alist grep-regexp-alist)
      ...)
  ...
  )
换句话说,它用
grep regexp-alist
本地覆盖
编译错误regexp-alist
,因此您需要在那里添加正则表达式。或者更好的办法是用

(let (compile-command
      (compilation-error-regexp-alist ack-regexp-alist)
      ...)
  ...
  )

最后,我仍然推荐使用regex,因为文件名似乎不能正常工作。它看起来更完整(虽然更复杂),我对此很满意。

感谢您帮助定义列表。但是,我仍然不确定如何将其传递给compile命令。当前输出似乎确实关心
ack regexp-alist
,尽管我确实关心
(setq编译错误regexp-alist(append编译错误regexp-alist ack regexp-alist))
,当我使用
M-x compile
手动运行ack时,它对我有效(尽管文件regexp工作不太正常)。您必须做的一件事是确保更新ack regexp列表。多次计算
defvar
不会改变设置后的值
C-h v ack regexp alist RET
将显示
ack regexp alist
的当前值。对于编译错误regexp alist,同样如此。再次感谢。我仍然很困惑,我编辑了我的问题,以显示在你的建议之后我的处境。再次感谢。我正试着全速前进。输出看起来很好。但有两个恼人的缺点:1。在输出缓冲区中,必须按搜索词本身的enter键才能跳转到代码。在行的其他任何位置按Enter键都不起作用。2.搜索的词不会自动填入光标下的词。这让我想坚持到目前为止。我将尝试您的解决方案并让您知道。完全确认的另一个主要缺点是:执行新搜索会杀死旧的结果缓冲区!
(let (compile-command
      (compilation-error-regexp-alist ack-regexp-alist)
      ...)
  ...
  )