Emacs compilation - mode to mark invalid lines as errors
I have a default issue compilation-error-regexp-*
matching any row to two separate columns as an error code
example: file:15:
will refer to a string 15
in the pathfile
But unfortunately it # file:15:
now refers to a path # file
that doesn't exist.
Try compiling in perl or python mode (it is valid in both languages) and you will understand my problem:
print "# file:15:";
I can't ignore this because I activated compilation-auto-jump-to-first-error
, which is very handy, but now it pops up in the file browser trying to open this nonexistent file # file:15:
.
I've already checked compilation-error-regexp-alist
and compilation-error-regexp-alist-alist
, but my perl settings don't include such a regex and I don't even have any settings for python.
I have checked with "emacs -Q" to make sure these are not my settings.
M-x compile RET python /tmp/py.py RET
with the above code will be highlite # file: 15: as an error string
Question: how can I override this regex or get rid of it?
amuses LanX
source to share
UPDATE: nope option grep-regexp-alist
for empty list didn't solve it.
OK I think I found the problem.
A glance at compile.el showed that grep-regexp-alist
"(why ???) is also evaluated.
And someone changed the first entry to
(("^\\(.+?\\)\\(:[ ]*\\)\\([0-9]+\\)\\2" 1 3)
...
... The + means anything is implied between the start and the first colon, including the name of the space and hashes.
Not sure how to turn off the regex meant for grep output when the script is compiled, will update as soon as I know it.
source to share
OK
I dug into compile mode sources, but I was unable to determine the origin of this greedy standard regex.
But I found a workaround!
You need to define your own regex that matches the same strings before the default regex is executed, and should fix 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 that start with a character or forward slash and no spaces or # in between are matched. Any other leading characters are ignored.
Of course, you still need to add the old regex for typical Perl error messages, I left that for readability.
And you will need to do this for each programming mode ...
NTN LanX
source to share