Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I filter compilation output only for a specific mode or buffer in Emacs?

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.
like image 903
viam0Zah Avatar asked Nov 06 '22 21:11

viam0Zah


1 Answers

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))))
like image 133
Nathaniel Flath Avatar answered Nov 15 '22 06:11

Nathaniel Flath