Emacs中如何实现错误回溯?

发布于 2024-11-16 02:36:25 字数 983 浏览 4 评论 0原文

我正在用 Ocaml 编写一个编译器。例如,当我在终端中使用 make 编译和测试它时,tracback 效果很好:

export OCAMLRUNPARAM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure("interp.ml", 45, 21)
Called from file "interp.ml", line 97, characters 72-86
Called from file "list.ml", line 74, characters 24-34
Called from file "interp.ml", line 108, characters 9-35
Called from file "main.ml", line 54, characters 4-17
make: *** [all] Error 2

但是当我在 Emacs 中通过 Meta-xcompile 编译并测试它时,然后make,它不会在缓冲区中显示回溯部分:

make
export OCAMLRUNPARAM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure("interp.ml", 45, 21)
make: *** [all] Error 2

Compilation exited abnormally with code 2 at Sat Jun 18 19:03:04

我的 .emacs 中有一部分是我从朋友那里复制的,用于进行回溯:http://paste.ubuntu.com/628838/

谁能告诉我如何修改我的 . emacs 以便它像在终端中一样显示回溯?非常感谢

I am writing a compiler in Ocaml. The tracback works well when I compile and test it with make in a terminal, for instance:

export OCAMLRUNPARAM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure("interp.ml", 45, 21)
Called from file "interp.ml", line 97, characters 72-86
Called from file "list.ml", line 74, characters 24-34
Called from file "interp.ml", line 108, characters 9-35
Called from file "main.ml", line 54, characters 4-17
make: *** [all] Error 2

But when I compile and test it in my Emacs by Meta-x compile followed by make, it does not show the traceback part in the buffer:

make
export OCAMLRUNPARAM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure("interp.ml", 45, 21)
make: *** [all] Error 2

Compilation exited abnormally with code 2 at Sat Jun 18 19:03:04

There is a part in my .emacs to do traceback that I copied from a friend: http://paste.ubuntu.com/628838/

Could anyone tell me how to amend my .emacs so that it shows traceback as in a terminal? Thank you very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第几種人 2024-11-23 02:36:25

您在哪里编写export OCAMLRUNPARAM=b

如果您在 makefile 中编写此内容(↹ 代表制表符):

↹export OCAMLRUNPARAM=b
↹./Simpler-Basic test.sib

那么它不起作用,因为每个 makefile 命令都在单独的 shell 中执行,因此环境变量分配在第一行完成后消失。您可以将这两行组合成一个逻辑行:

↹export OCAMLRUNPARAM=b; \
↹./Simpler-Basic test.sib

如果您在 Emacs 中运行 Ocaml 程序时始终需要回溯,请在 .emacs 中设置环境变量:

(setenv "OCAMLRUNPARAM" "b")

为了让 Emacs 识别回溯消息作为带有位置的错误消息,您需要将它们注册在 compilation-regexp-alist。在您的 .emacs 中放入类似的内容(未经测试):

(eval-after-load "caml"
  (add-to-list 'compilation-regexp-alist
               '("\\(^Raised at\\|Called from\\) file \"\\([^"\n]+\\)\", line \\([0-9]+\\)"
                 2 3)))

Where did you write export OCAMLRUNPARAM=b?

If you wrote this in a makefile (↹ stands for a tab):

↹export OCAMLRUNPARAM=b
↹./Simpler-Basic test.sib

then it doesn't work because each makefile command is executed in a separate shell, so the environment variable assignment vanishes after the first line completes. You can combine the two lines in a single logical line instead:

↹export OCAMLRUNPARAM=b; \
↹./Simpler-Basic test.sib

If you always want backtraces when running an Ocaml program from within Emacs, set the environment variable in your .emacs:

(setenv "OCAMLRUNPARAM" "b")

In order for Emacs to recognize the backtrace messages as error messages with a location, you need to register them in compilation-regexp-alist. Put something like this in your .emacs (untested):

(eval-after-load "caml"
  (add-to-list 'compilation-regexp-alist
               '("\\(^Raised at\\|Called from\\) file \"\\([^"\n]+\\)\", line \\([0-9]+\\)"
                 2 3)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文