请教:编译输出的错误信息定位文件某一行

由于emacs的 compilation-mode 默认的正则语法不能识别vcs的输出错误信息,所以我想自己添加一个。 我可以直接在 compile.el 文件中的 compilation-error-regexp-alist-alist 函数中添加我自己想要的正则吗?还是有更好的解决办法?

不用去 compile.el 里面,直接 (add-to-list 'compilation-error-regexp-alist xxxx) 就可以了

以前折腾的,也搞不清为啥写这么复杂……

(defun my-config-error-regexp-add-emacs (regexp-alist)
  " add regexp-alist to `compilation-error-regexp-alist'
Called by `compilation-mode-hook'.  This allows \\[next-error] to
find the errors."
  (interactive)
  (mapcar
   (lambda (item)
     (if (not (memq (car item) compilation-error-regexp-alist))
         (progn
           (push (car item) compilation-error-regexp-alist)
           (push item compilation-error-regexp-alist-alist))
       )
     )
   regexp-alist))

(setq fm-error-regexp-emacs-alist
            '(
              (fm-WARNING
               "\\([^ \t\n,]+\\):\\([0-9]+\\):.*\[WARNING\]" 1 2 nil 2)
              (fm-ERROR
               "\\([^ \t\n,]+\\):\\([0-9]+\\):.*\[ERROR\]" 1 2 nil 2)
              ))
      (require 'compile)
      (my-config-error-regexp-add-emacs fm-error-regexp-emacs-alist))

按照这个方法搞定了,感谢! 还有一个问题,关于最后编译结果,我看到 compile.el文件中说明关于info、warning、error的值,0是info,1是warning,2是error,这个没有找到在哪个位置可以修改,最后编译报错的选项可以根据上面定位错误的正则表达式修改吗?

另外,已经匹配了我自己添加的错误信息,其他不是错误信息的行却匹配了其他语法,这个有没有办法取消掉?目前只想让错误信息匹配我当前使用的编译器语法。

编辑: 目前暂时只是把emacs中verilog-mode.el中其他alist注释掉了,可以只显示自己添加的正则alist。感觉有点不太好 :joy: