如何防止emacs在批处理模式下切断堆栈跟踪?

Rya*_*son 5 emacs stack-trace batch-processing

我正在为Emacs开发一个软件项目,它有一些可以批处理模式运行的测试,用于快速回归测试.但是,当测试失败时,终端中的堆栈跟踪会在顶部被切断,因此我必须在交互式Emacs会话中再次运行失败测试,​​以查看完整堆栈恍惚状态并找出错误实际发生的位置.是否有一些我可以修改的变量将扩展Emacs以批处理模式打印到终端的堆栈跟踪的最大长度?

如果你想要一个简单的测试用例来产生一个非常深的堆栈跟踪,这将是一个无限递归的简单案例,当emacs到达某个深度时它会中止:

emacs -Q -batch --eval '(defun f () (f))' -f toggle-debug-on-error -f f
Run Code Online (Sandbox Code Playgroud)

以下是我的系统上该命令的确切输出:

Debug on Error enabled globally
...
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  f()
  command-line-1(("--eval" "(defun f () (f))" "-f" "toggle-debug-on-error" "-f" "f"))
  command-line()
  normal-top-level()
Run Code Online (Sandbox Code Playgroud)

特别要注意的是,后面的行Debug on Error enabled globally实际上是输出中的省略号,如果不以交互方式运行,就无法更深入地进入堆栈跟踪.

phi*_*ils 2

看起来这debugger-batch-max-lines就是您所追求的:

M-x customize-group RET debugger RET

(defcustom debugger-batch-max-lines 40
  "Maximum lines to show in debugger buffer in a noninteractive Emacs.
When the debugger is entered and Emacs is running in batch mode,
if the backtrace text has more than this many lines,
the middle is discarded, and just the beginning and end are displayed."
  :type 'integer
  :group 'debugger
  :version "21.1")
Run Code Online (Sandbox Code Playgroud)