Note that there are some explanatory texts on larger screens.

plurals
  1. POEmacs compilation-mode regex for multiple lines
    text
    copied!<p>So I have a tool lints python changes I've made and produces errors and warnings. I would like this to be usable in compile mode with Emacs, but I have an issue. The file name is output only once at the beginning, and then only line numbers appear with the errors and warnings. Here's an example:</p> <pre><code>Linting file.py E0602: 37: Undefined variable 'foo' C6003: 42: Unnecessary parens after 'print' keyword 2 new errors, 2 total errors in file.py. </code></pre> <p>It's very similar to pylint, but there's no output-format=parseable option. I checked the documentation for compilation-error-regexp-alist, and found something promising:</p> <blockquote> <p>If FILE, LINE or COLUMN are nil or that index didn't match, that<br> information is not present on the matched line. In that case the<br> file name is assumed to be the same as the previous one in the<br> buffer, line number defaults to 1 and column defaults to<br> beginning of line's indentation.</p> </blockquote> <p>So I tried writing a regexp that would optionally match the file line and pull it out in a group, and then the rest would match the other lines. I assumed that it would first match</p> <pre><code>Linting file.py E0602: 37: Undefined variable 'foo' </code></pre> <p>and be fine. Then it would continue and match</p> <pre><code>C6003: 42: Unnecessary parens after 'print' keyword </code></pre> <p>with no file. Since there was no file, it should use the file name from the previous match right? Here's the regexp I'm using:</p> <pre><code>(add-to-list 'compilation-error-regexp-alist 'special-lint) (add-to-list 'compilation-error-regexp-alist-alist '(special-lint "\\(Linting \\(.*\\)\\n\\)?\\([[:upper:]][[:digit:]]+:\\s-+\\([[:digit:]]\\)+\\).*" 2 4 nil nil 3)) </code></pre> <p>I've checked it with re-builder and manually in the scratch buffer. It behaves as expected. the 2nd group is the file name, the 4th is the line number, and the 3rd is what I want highlighted. Whenever I try this, I get the error:</p> <pre><code>signal(error ("No match 2 in highlight (2 compilation-error-face)")) </code></pre> <p>I have a workaround for this that involves transforming the output before the compile module looks at it, but I'd prefer to get rid of that and have a "pure" solution. I would appreciate any advice or pointing out any dumb mistakes I may have made.</p> <p><strong>EDIT</strong></p> <p>Thomas' pseudo code below worked quite well. He mentioned that doing a backwards re search could mess up the match data, and it did. But that was solved by adding the <code>save-match-data</code> special form before <code>save-excursion</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload