Emacs中如何实现错误回溯?
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在哪里编写
export OCAMLRUNPARAM=b
?如果您在 makefile 中编写此内容(↹ 代表制表符):
那么它不起作用,因为每个 makefile 命令都在单独的 shell 中执行,因此环境变量分配在第一行完成后消失。您可以将这两行组合成一个逻辑行:
如果您在 Emacs 中运行 Ocaml 程序时始终需要回溯,请在
.emacs
中设置环境变量:为了让 Emacs 识别回溯消息作为带有位置的错误消息,您需要将它们注册在
compilation-regexp-alist
。在您的.emacs
中放入类似的内容(未经测试):Where did you write
export OCAMLRUNPARAM=b
?If you wrote this in a makefile (↹ stands for a tab):
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:
If you always want backtraces when running an Ocaml program from within Emacs, set the environment variable in your
.emacs
: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):