Difference between revision 18 and current revision

No diff available.

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

;; 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

For more information on how to brew your own compilation-error-regexp-alist type M-x describe-variable <RET> compilation-error-regexp-alist.


The above did not work for me, but the following link was helpful: 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, 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 .../lisp/progmodes):

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


a (require 'compile) , just beffor the (add-hook ... works fine

The problem

  • M-x compile should trigger a compilation buffer with errors found by jslint… but it doesn’t.

A solution

    (require 'compile)
    (defun jslint-errors ()
      (make-local-variable 'compilation-error-regexp-alist)
      (setq compilation-error-regexp-alist
              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)


– Notio

Question Shouldn’t there be extra parentheses around the compilation-error-regexp-alist:

    (setq compilation-error-regexp-alist
              1 2 3)));

I didn’t try this example, but got no matches for my own regexp unless I used double parentheses around the single-element alist.

– Lukas