emacs: Can I set compilation-error-regexp-alist in a mode hook fn?

Posted by Cheeso on Stack Overflow See other posts from Stack Overflow or by Cheeso
Published on 2010-03-17T20:38:15Z Indexed on 2010/03/17 20:41 UTC
Read the original article Hit count: 512

Filed under:
|

I am trying to set the compilation-error-regexp-alist in a function that I add as a mode hook.

(defun cheeso-javascript-mode-fn ()
  (turn-on-font-lock)

   ...bunch of other stuff

  ;; for JSLINT
  (make-local-variable 'compilation-error-regexp-alist)
  (setq compilation-error-regexp-alist
        '(
 ("^[ \t]*\\([A-Za-z.0-9_: \\-]+\\)(\\([0-9]+\\)[,]\\( *[0-9]+\\))\\( Microsoft JScript runtime error\\| JSLINT\\): \\(.+\\)$" 1 2 3)
 ))

  ;;(make-local-variable 'compile-command)
  (setq compile-command
       (let ((file (file-name-nondirectory buffer-file-name)))
         (concat "%windir%\\system32\\cscript.exe \\cheeso\\bin\\jslint.js "  file)))

)

(add-hook 'javascript-mode-hook 'cheeso-javascript-mode-fn)

The mode hook runs. The various things I Set in the mode hook work. The compile-command gets set. But for some reason, the compilation-error-regexp-alist value doesn't take effect.

If I later do a M-x describe-variable on compilation-error-regexp-alist, it shows me the value I think it should have. But .. the errors in the compilation buffer don't get highlighted, and M-x next-error does not work.

alt text

If I add the error regexp value to the compilation-error-regexp-alist via setq-default, like this:

(setq-default compilation-error-regexp-alist
  '(
     ... jslint regexp here ...
     ... many other regexp's here...
   ))

...then it works. The errors in the compilation buffer get properly highlighted and M-x next-error functions as expected.

© Stack Overflow or respective owner

Related posts about emacs

Related posts about jslint