2010-03-17 33 views
2

我正在嘗試將compilation-error-regexp-alist設置爲一個我添加爲模式鉤子的函數。emacs:我可以在模式鉤子fn中設置編譯錯誤 - regexp-alist嗎?

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

模式掛鉤運行。我在模式掛鉤工作中設置的各種東西。 compile-command被設置。但由於某些原因,compilation-error-regexp-alist值不生效。

如果我後來在compilation-error-regexp-alist上做了M-x describe-variable,它顯示出我認爲它應該有的值。但是..編譯緩衝區中的錯誤不會突出顯示,並且M-x next-error不起作用。

alt text http://i40.tinypic.com/drb3g4.jpg

如果我通過setq-default添加錯誤的正則表達式的值到compilation-error-regexp-alist,就像這樣:

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

...然後它的作品。編譯緩衝區中的錯誤得到正確突出顯示,M-x next-error按預期運行。

alt text http://i40.tinypic.com/10nclxv.jpg

回答

2

我不相信compile命令繼承你爲compilation-error-regexp-alist設置本地值。解決方案是自定義*compilation*緩衝區的鉤子,請參閱compilation-mode-hook和編譯 - 開始鉤子。

+0

aha!非常感謝你。 – Cheeso 2010-03-17 21:02:56

相關問題