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

I have an HTML page with it turned on html-mode. I call a function sgml-validateto check for any markup errors. It is based on compilation-mode. I want to remove some warnings from compilation output, so I wrote a function and connected it to compilation-filter-hook(this variable is not documented, but compilation-filtercalls it). Everything is working. My problem is how can I ensure that the filter function is only called when the compilation process starts on an HTML page (via sgml-validate)?

I see two methods, but none of them worked:

  • First, I can check the value major-mode. But it always returns compilation-modeas it is included in the buffer *compilation*. (I found the filter function in the source codegrep+ , and they checked the value major-mode. I cannot figure out how it can work correctly.)
  • Another idea was that I simply attached the filter function to the HTML file buffer, but for the same reasons it could not work, since the output of the compilation process goes to a separate buffer.
+5
source share
2 answers

It looks like you can tell smgl-validate to have it filter before doing all the other operations. For example:

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

, , compilation-start mode, . , compilation-mode, , .

, sgml-validate mode compilation-start, .

(, ).

+1

All Articles