emacs compilation-mode marking wrong lines as errors

723 views Asked by At

I have a problem with a default compilation-error-regexp-* matching any line with two separate columns as error-code

example: file:15: will link to line 15 in path file

But unfortunately does # file:15: now link to path # file which doesn't exists.

Please try compiling the following in either perl or python mode (it's valid in both languages), and you'll understand my problem:

print "# file:15:";

I can't ignore this, cause I activated compilation-auto-jump-to-first-error which is very handy but now it pops up a file-browser trying to open this non existing file # file:15:.

I already checked compilation-error-regexp-alist and compilation-error-regexp-alist-alist but my perl settings do not include such a regex and I don't even have any setting for python.

I checked with "emacs -Q" to be sure that it's not any of my settings.

M-x compile RET python /tmp/py.py RET

with above code will highlite # file:15: as error line

Question: how can I redefine this regex or get rid of it?

cheers LanX

2

There are 2 answers

0
LanX On

UPDATE: nope setting grep-regexp-alist to an empty list didn't solve it.

OK I think I found the problem.

Looking into compile.el revealed that grep-regexp-alist is also evaluated" (why???).

And someone changed the first entry to

 (("^\\(.+?\\)\\(:[       ]*\\)\\([0-9]+\\)\\2" 1 3)
   ...

The .+ means anything between start and first colon is taken as filename including whitespace and hashes.

Don't know yet how to disable a regex meant for grep output when compiling script, will update as soon as I know.

0
LanX On

OK

I digged into the sources of compilation mode but I wasn't able to identify the origin of this greedy default regexp.

But I found a workaround!

One has to define an own regexp which matches the same lines before the default regexp can do and has to correct the matching groups to avoid strange characters.

This is a proof of concept

(add-to-list 'compilation-error-regexp-alist-alist '(perl "^.*?\\([a-zA-Z/][^ \n#]+\\):\\([0-9]+\\):" 1 2))

Now only paths starting with a character or a slash and w/o whitespace or # in between are matched. Any other leading characters are ignored.

Of course you'll still need to append the old regexp for typical Perl error messages, I left this out for readability.

And you'll have to do it for each programming mode...

HTH LanX