variables. This can be used for remote hosts.
** Emacs now prints a backtrace when signaling an error in batch mode. This
-makes debugging Emacs Lisp scripts run in batch mode easier.
+makes debugging Emacs Lisp scripts run in batch mode easier. If you
+want to disable this behavior, set 'backtrace-on-error-noninteractive'
+to nil.
\f
* Editing Changes in Emacs 28.1
debugging. Make sure to use `debug' unconditionally to not interfere with
ERT or other packages that install custom debuggers. */
if (!debugger_called && !NILP (error_symbol)
- && (NILP (clause) || EQ (h->tag_or_ch, Qerror)) && noninteractive)
+ && (NILP (clause) || EQ (h->tag_or_ch, Qerror)) && noninteractive
+ && backtrace_on_error_noninteractive)
{
ptrdiff_t count = SPECPDL_INDEX ();
specbind (Vdebugger, Qdebug);
still determine whether to handle the particular condition. */);
Vdebug_on_signal = Qnil;
+ DEFVAR_BOOL ("backtrace-on-error-noninteractive",
+ backtrace_on_error_noninteractive,
+ doc: /* If non-nil and Emacs is running noninteractively,
+print a backtrace on encountering an unhandled error. */);
+ backtrace_on_error_noninteractive = true;
+
/* The value of num_nonmacro_input_events as of the last time we
started to enter the debugger. If we decide to enter the debugger
again when this is still equal to num_nonmacro_input_events, then we
(search-forward " foo()")
(search-forward " normal-top-level()")))))
+(ert-deftest eval-tests/backtrace-in-batch-mode/inhibit ()
+ (let ((emacs (expand-file-name invocation-name invocation-directory)))
+ (skip-unless (file-executable-p emacs))
+ (with-temp-buffer
+ (let ((status (call-process
+ emacs nil t nil
+ "--quick" "--batch"
+ (concat "--eval="
+ (prin1-to-string
+ '(progn
+ (defun foo () (error "Boo"))
+ (let ((backtrace-on-error-noninteractive nil))
+ (foo))))))))
+ (should (natnump status))
+ (should-not (eql status 0)))
+ (should (equal (string-trim (buffer-string)) "Boo")))))
+
(ert-deftest eval-tests/backtrace-in-batch-mode/demoted-errors ()
(let ((emacs (expand-file-name invocation-name invocation-directory)))
(skip-unless (file-executable-p emacs))