如何在 Emacs 中仅过滤特定模式或缓冲区的编译输出?
我有一个 HTML 页面,启用了 html-mode
。 我调用函数 sgml-validate 来检查是否有任何标记错误。 它基于编译模式
。 我想从编译输出中删除一些警告,因此我编写了一个函数并将其挂钩到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 returnscompilation-mode
, since that is enabled on the*compilation*
buffer. (I found a filter function in the source code ofgrep+
, and they did check the value ofmajor-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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您可以建议 smgl-validate 以便它在执行所有其他操作之前执行过滤。 例如:
It sounds like you can advise smgl-validate so that it performs the filtering before it performs all it's other operations. For example:
同时,我发现
compilation-start
接受一个可选参数mode
,它将成为编译缓冲区的主要模式。 因此,我可以创建一个从编译模式派生的主要模式,并在那里定义我的过滤器函数,现在它连接到正确的缓冲区。现在唯一的问题是
sgml-validate
不允许我在compilation-start
上设置mode
参数,但这是另一个问题。(当然,我不认为这是最终的解决方案。)
Meanwhile, I found that
compilation-start
accepts an optional argumentmode
, which will be the major mode for the compilation buffer. So I can create a major mode derived fromcompilation-mode
, and define there my filter function now hooked to the proper buffer.The only problem is now that
sgml-validate
does not allow me to set themode
argument oncompilation-start
, but that's another question.(I don't consider this the ultimate solution, of course.)