且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何跟踪“失败” Emacs中的错误?

更新时间:2023-11-24 14:02:16

请参阅以下错误报告中的一些elisp添加到您的.emacs,以便编译主要模式知道如何解析OCaml回溯报告。



以下是建议的代码(加图形模式钩子):

 (defun caml-change-error- alist-for-backtraces()
Hook将编译错误 - regexp-alist变量更改为
搜索错误位置的ocaml回溯
(interactive)
progn
(setq compilation-error-regexp-alist-alist
(附加
'((caml-backtrace
^ * \\(? \ |从\\中调用文件\\(\?\\)\\([^,\\\\
\t] + \\\ \\)\\1,\
行? \\([0-9] + \\) - ?\\([0-9] + \\)?\\(?:$ \\ |,\\ \\
\\(?: characters?\\([0-9] + \\) - ?\\([0-9] + \\)?: ?\\)
2(3..4)(.6)))
compilation-error-regexp-alist-alist))
( setq compilation-error-regexp-alist
(附加编译错误 - regexp-alist'(caml-backtrace)))))

(add-hook'caml-mode-hook'
(add-hook'tuareg-mode-hook'caml-change-error-alist-for-backtraces)


(defun caml-change-error-alist-for-assert-failure()
Hook将编译错误 - regexp-alist变量更改为
搜索错误位置的断言失败消息
(interactive)
(progn
(setq compilation-error-regexp-alist-alist
(append
'((caml-assert-failure
Assert_fail ure(\\\([^,\\\\
\t]] \\ \\)\,\\([0-9] + \\\ \\),\\([0-9] + \\))
1 2 3))
compilation-error-regexp-alist-alist))
setq compilation-error-regexp-alist
(append-compiler-regexp-alist'(caml-assert-failure)))))

(add-hook'caml-mode-钩子'caml-change-error-alist-for-assert-failure)
(add-hook'tuareg-mode-hook'caml-change-error-alist-for-assert-failure)


I am writing OCaml under Emacs. I have already configured Emacs so that Meta-x compile and make -k gives warnings with hyperlink. But for errors raised by failwith, it can not give a hyperlink, for instance:

analyzing (ZONE)...
Fatal error: exception Failure("to do")
Raised at file "pervasives.ml", line 22, characters 22-33
Called from file "list.ml", line 69, characters 12-15
make: *** [all] Error 2

Compilation exited abnormally with code 2 at Fri Jan 27 18:44:10

I have many failwith "to do" in my code, and need to know which one raises the error, does anyone know how to let Emacs locate this kind of error?

See the following bug report for some elisp to add to your .emacs, so that the compilation major mode knows how to parse OCaml backtrace reports.

Here is the suggested code (plus tuareg-mode hooks):

(defun caml-change-error-alist-for-backtraces ()
  "Hook to change the compilation-error-regexp-alist variable, to
   search the ocaml backtraces for error locations"
  (interactive)
  (progn
    (setq compilation-error-regexp-alist-alist
          (append
           '((caml-backtrace
"^ *\\(?:Raised at\\|Called from\\) file \\(\"?\\)\\([^,\" \n\t<>]+\\)\\1,\
 lines? \\([0-9]+\\)-?\\([0-9]+\\)?\\(?:$\\|,\
\\(?: characters? \\([0-9]+\\)-?\\([0-9]+\\)?:?\\)?\\)"
              2 (3 . 4) (5 . 6)))
           compilation-error-regexp-alist-alist))
    (setq compilation-error-regexp-alist
          (append compilation-error-regexp-alist '(caml-backtrace)))))

(add-hook 'caml-mode-hook 'caml-change-error-alist-for-backtraces)
(add-hook 'tuareg-mode-hook 'caml-change-error-alist-for-backtraces)


(defun caml-change-error-alist-for-assert-failure ()
  "Hook to change the compilation-error-regexp-alist variable, to
   search the assert failure messages for error locations"
  (interactive)
  (progn
    (setq compilation-error-regexp-alist-alist
          (append
           '((caml-assert-failure
              "Assert_failure(\"\\([^,\" \n\t<>]+\\)\", \\([0-9]+\\), \\([0-9]+\\))"
              1 2 3))
           compilation-error-regexp-alist-alist))
    (setq compilation-error-regexp-alist
          (append compilation-error-regexp-alist '(caml-assert-failure)))))

(add-hook 'caml-mode-hook 'caml-change-error-alist-for-assert-failure)
(add-hook 'tuareg-mode-hook 'caml-change-error-alist-for-assert-failure)