4

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

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-x compilemake它不会在缓冲区中显示回溯部分:

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,以便它在终端中显示回溯?非常感谢你

4

1 回答 1

6

你在哪里写的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)))
于 2011-06-18T17:44:42.213 回答