I'm running a command with compile
so I can link from error messages to the associated source, but I need to transform a chunk of the content of matched lines to get the file to link to. (The line shows a clojure namespace, like foo-bar.quux
, which needs to be transformed into foo_bar/quux.clj
.)
The documentation of compilation-error-regexp-alist
says, in part,
Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK HIGHLIGHT...]). ... FILE can also have the form (FILE FORMAT...), where the FORMATs (e.g. \"%s.c\") will be applied in turn to the recognized file name, until a file of that name is found. Or FILE can also be a function that returns (FILENAME) or (RELATIVE-FILENAME . DIRNAME). In the former case, FILENAME may be relative or absolute.
When I add entries to compilation-error-regexp-alist-alist
and compilation-error-regexp-alist
with a function in FILE
position, my function is called with no arguments. How do I get the matched line inside that function?
Opening compile.el
and then searching with C-s (funcall
jumped me to:
(setq file (if (functionp file) (funcall file)
(match-string-no-properties file))))
which seems to be the relevant spot and shows that the functions is indeed called with no arguments and that the match-data
is still very much valid, so you can extract the file name with (match-string <the-file-sub-group>)
.