我如何才能在Emacs中仅针对特定模式或缓冲区过滤编译输出?(How can I filter compilation output only for a specific mode or buffe

编程入门 行业动态 更新时间:2024-10-27 10:21:45
我如何才能在Emacs中仅针对特定模式或缓冲区过滤编译输出?(How can I filter compilation output only for a specific mode or buffer in Emacs?)

我有一个HTML页面,启用了html-mode 。 我调用函数sgml-validate来检查是否有标记错误。 它基于compilation-mode 。 我想从编译输出中删除一些警告,所以我编写了一个函数并将其挂钩到compilation-filter-hook (该变量没有记录,但compilation-filter调用它)。 一切正常。 我的问题是,如何确保我的过滤器函数只在我开始在HTML页面上编译过程(通过sgml-validate )时被调用?

我看到两种方法,但都没有工作:

首先,我可以检查major-mode的价值。 但它总是返回compilation-mode ,因为它在*compilation*缓冲区中启用。 (我在grep+的源代码中找到了一个过滤函数,他们确实检查了major-mode的值,我不知道它是如何工作的。) 另一个想法是只将我的过滤器函数挂接到HTML文件的缓冲区,但出于类似的原因,它不能工作,因为编译过程的输出到了一个单独的缓冲区。

I have a HTML page, with html-mode enabled. I call function sgml-validate to check for any markup errors. It's based on compilation-mode. I want to remove some warnings from the compilation output, so I wrote a function and hooked it to compilation-filter-hook (this variable is not documented, but compilation-filter invokes it). Everything works. My problem is that how can I ensure my filter function only gets called when I started the compilation process on a HTML page (via sgml-validate)?

I see two methods, but none of them worked:

First, I can check the value of major-mode. But it always returns compilation-mode, since that is enabled on the *compilation* buffer. (I found a filter function in the source code of grep+, and they did check the value of major-mode. I can't figure out how can it work correctly.) The other idea was than to only hook my filter function to the HTML file's buffer, but for similar reasons it couldn't work as the output of compilation process goes to a seperate buffer.

最满意答案

听起来您可以建议smgl-validate,以便在它执行所有其他操作之前执行过滤。 例如:

(defadvice sgml-validate (around fix-filtering command activate) (let ((return-value ad-do-it)) (filter-function return-value))))

It sounds like you can advise smgl-validate so that it performs the filtering before it performs all it's other operations. For example:

(defadvice sgml-validate (around fix-filtering command activate) (let ((return-value ad-do-it)) (filter-function return-value))))

更多推荐

本文发布于:2023-08-07 04:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459597.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓冲区   模式   filter   Emacs   compilation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!