2

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?

duelin markers
  • 553
  • 3
  • 14
  • 1
    Calling the function is the correct behaviour (though I agree that's not very clever). As for getting the matched error, have you tried using `(match-string 0)`? – Malabarba Aug 05 '13 at 00:00

1 Answers1

2

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>).

Stefan
  • 27,908
  • 4
  • 53
  • 82
  • 1
    Works great. Thanks. I'm new to emacs lisp and surprised (and a little disturbed) at how much is done via mutable global state. – duelin markers Aug 05 '13 at 03:02