我是从艾玛奇开始的,但我不太懂埃利什。几乎什么都没有真的。
我想用ack代替grep。
下面是我在emacs内部使用ack的说明:el
现在我不喜欢在这个el文件中使用的输出格式,我希望输出是ack --group的输出。
所以我改变了:
(read-string "Ack arguments: " "-i" nil "-i" nil)至:
(read-string "Ack arguments: " "-i --group" nil "-i --group" nil)到目前一切尚好。但这使我失去了在输出缓冲区的行上单击-press_enter的能力。在最初的行为中,编译模式被用来跳转到选定的行。
我想我应该把一个regexp加入到默认模式中。默认模式的定义如下:
(define-compilation-mode ack-mode "Ack"
"Specialization of compilation-mode for use with ack."
nil)我还想将regexp [0-9]+:也添加为一个错误,因为这是输出程序的每一行都包含的内容(行号)。
我试图修改上面的define-compilation-mode以添加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))我在某个地方偷了它,并试图适应我的需要。不走运。
--编辑,伊万提议后的结果--
更新了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) 然后检查compilation-error-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,所以也许这样是对的。
在*ack*缓冲区中仍然没有链接或颜色。
发布于 2010-03-19 18:59:49
在ELPA上还有另一个ELPA包,我以前使用过它,并处理--group输出。
尽管如此,阅读compilation-error-regexp-alist的文档您可以看到它有如下形式:
(REGEXP FILE [LINE COLUMN TYPE HYPERLINK HIGHLIGHT...])在--group输出的情况下,您必须分别匹配文件和行,因此我认为您需要类似于(未经测试)的内容。
(defvar ack-regexp-alist
'(("^\\S +$" ;; match a file -- this could be better
0 ;; The file is the 1st subexpression
)
("^[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)
))
"Alist that specifies how to match rows in ack output.")-更新--
变量compilation-error-regext-alist是像(REGEXP ...)这样的符号或元素的列表。在compilation-error-regexp-alist-alist中查找符号以查找相应的元素。所以是的,这是有点奇怪,但更容易看到什么是打开和关闭,而不必看丑陋的雷克斯,猜猜他们做了什么。如果您要分发此命令,我建议将正则表达式添加到compilation-error-regexp-alist-alist中,然后在compilation-error-regext-alist中打开它,但在您使它正常工作之前,这还有些意义。
仔细观察ack.el,我注意到它使用
(let (compile-command
(compilation-error-regexp-alist grep-regexp-alist)
...)
...
)换句话说,它在本地用compilation-error-regexp-alist覆盖grep-regexp-alist,因此您需要在那里添加正则表达式。或者更好的办法是用
(let (compile-command
(compilation-error-regexp-alist ack-regexp-alist)
...)
...
)最后,我仍然推荐全黑,因为文件名regex似乎没有正常工作。它似乎更完整(虽然更复杂),我一直对此感到满意。
https://stackoverflow.com/questions/2478656
复制相似问题