代码之家  ›  专栏  ›  技术社区  ›  Cheeso

emacs:我可以在模式钩子fn中设置编译错误regexp-alist吗?

  •  2
  • Cheeso  · 技术社区  · 15 年前

    我正试着设置 compilation-error-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 获取设置。但出于某种原因, 编译错误regexp-alist 价值不起作用。

    如果我以后做一个 M-x describe-variable 编译错误regexp-alist ,它显示了我认为它应该具有的价值。但是…编译缓冲区中的错误不会突出显示,并且 M-x next-error 不起作用。

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

    如果我将error regexp值添加到 编译错误regexp-alist 通过 setq-default ,像这样:

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

    ……那就行了。编译缓冲区中的错误被正确地突出显示,并且 M-X下一个错误 功能如预期。

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

    1 回复  |  直到 15 年前
        1
  •  2
  •   Trey Jackson    15 年前

    我不相信 compile 命令 继承 为其设置的本地值 compilation-error-regexp-alist . 解决方案是为 *compilation* 缓冲区本身,请参见 compilation-mode-hook 以及编译开始钩子。