compilation-error-regexp-alist is used to parse the CompilationMode buffer, and allow you to jump from compile error messages directly to the problem in the source line.
The default entries in Emacs work for many compilers, but not all, so here’s some tips to allow you to add support for your own compiler. Or you might find it useful if you have your own weird parser, custom build scripts, or even perl HTML templating engine, you can use this method to filter through the compile output, and take you directly to the problem.
The operative part should be a simple regexp, and it is, but the tricky bit is getting it to work. Some subtle differences between Emacs and XEmacs are particularly tedious. In Emacs you can just add to
compilation-error-regexp-alist, but in XEmacs you’re supposed to add to
compilation-error-regexp-alist-alist and then call
compilation-build-compilation-error-regexp-alist to construct the plain list. And for extra confusion Emacs 22 also has a
compilation-error-regexp-alist-alist, but in a different format (and not needing an explicit “build”).
Here’s an example by TimOCallaghan to support the native HP/Compaq OpenVms C compiler output in XEmacs.
;; add vms to the systems list for the error alist creation (pushnew '(vms ("^at line number \\([0-9]+\\) in file [A-Z]+:\\[[A-Z0-9\\.]+\\]\\([A-Z0-9]+\\.[A-Z]+\\)" 2 1)) compilation-error-regexp-alist-alist) ;; the only system i want to support compiler output from is VMS (setq compilation-error-regexp-systems-list (list 'vms)) ;; rebuild the compilation-error-regexp-alist (compilation-build-compilation-error-regexp-alist)
For more information on how to brew your own
M-x describe-variable <RET> compilation-error-regexp-alist.
The above did not work for me, but the following link was helpful: http://www.tddft.org/programs/octopus/wiki/index.php/Emacs_helpers. To get g95 to work first tried to add to f90-mode-hook:
(add-hook 'f90-mode-hook (lambda () (add-to-list 'compilation-error-regexp-alist '("^In file \\(.*?\\):\\([0-9]+\\)$" 1 2)) ))
Unfortunately this only worked if I evaluated it manualy (with M-x eval-region or M-x load-file), but when I tried running it from .emacs it gave a “File mode specification error”. I suspect that is some sort of bug in Emacs (my version is 18.104.22.168, on Ms Windows), so I ended up adding the following line to the definition of
compilation-error-regexp-alist-alist in compile.el (located in
(g95 "^In file \\(.*?\\):\\([0-9]+\\)$" 1 2)
(and then did M-x byte-compile-file compile.el). Of course this will not survive a reinstallation of Emacs!
Usually additions to
compilation-error-regexp-alist (etc) can only be made after
compilation-mode has loaded. I use
(eval-after-load "compile" ...), as I suspect the standard
compilation-mode hooks are run too late to make additions there.
(require 'compile) , just beffor the
(add-hook ... works fine
M-x compileshould trigger a compilation buffer with errors found by jslint… but it doesn’t.
(require 'compile) (defun jslint-errors () (make-local-variable 'compilation-error-regexp-alist) (setq compilation-error-regexp-alist '("^jslint:\\([_[:alnum:]-/]*.js\\):\\([[:digit:]]+\\):\\([[:digit:]]+\\):.*$" 1 2 3)); "1" means that the file name is matched by the first ; subexpression : \\([_[:alnum:]-/]*.js\\). See ; compilation-error-regexp-alist for the meaning of "2 3". (make-local-variable 'compile-command) (let ((jslint4java "~/path/to/jslint4java-2.0.4.jar ") (java "/path/to/java -jar ")) (setq compile-command (concat java jslint4java buffer-file-name)))) (add-hook 'js-mode-hook 'jslint-errors)