summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2026-05-01 13:17:20 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2026-05-04 12:49:35 -0400
commita952324e9be37869158e8a9cc4f676fa6113a343 (patch)
treeac60bdadf2e66a1fd940f3b5e84a8b752fea54d3 /test
parent9c0a699c59ebe127950cf561b98a40f6e5916a03 (diff)
keyboard.c: Allow SIGINT to `quit` in batch mode, instead of exit
In terminal sessions, SIGINT is turned into a `quit` ELisp signal, but in batch it has traditionally killed Emacs. It can be very useful to cause a `quit` from outside the process when running in batch (e.g. for "batch" sessions that provide a REPL via stdin/out), so add a new var 'kill-emacs-on-sigint' to control that behavior. (bug#80942) * src/keyboard.c (handle_interrupt_signal): Obey `kill_emacs_on_sigint`. (init_keyboard): Use `deliver_interrupt_signal` for SIGINT also for batch sessions. (syms_of_keyboard): New variable `kill_emacs_on_sigint`. * test/src/keyboard-tests.el (keyboard-sigint-to-quit): New test. * doc/emacs/cmdargs.texi (Initial Options): Mention the effect of `kill-emacs-on-sigint` in batch mode.
Diffstat (limited to 'test')
-rw-r--r--test/src/keyboard-tests.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/src/keyboard-tests.el b/test/src/keyboard-tests.el
index ae47e4b3b4b..e4a1bf36a63 100644
--- a/test/src/keyboard-tests.el
+++ b/test/src/keyboard-tests.el
@@ -81,6 +81,34 @@
(should-error (read-event "foo: "))
(should-error (read-char-exclusive "foo: "))))
+(ert-deftest keyboard-sigint-to-quit () ;; bug#80942
+ (with-temp-buffer
+ (let* ((exit-msg "Exit via Quit")
+ (proc
+ (make-process
+ :name "keyboard-sigint-to-quit"
+ :buffer (current-buffer)
+ :command
+ `(,(expand-file-name invocation-name invocation-directory)
+ "-Q" "--batch" "--eval"
+ ,(prin1-to-string
+ `(progn (setq kill-emacs-on-sigint nil)
+ (message "Ready!")
+ (condition-case nil
+ (dotimes (_ 3) (sit-for 1))
+ (quit (message "%s" ,exit-msg)))))))))
+ (while (progn (accept-process-output proc 1.0)
+ (goto-char (point-min))
+ (not (re-search-forward "Ready!" nil t)))
+ ) ;; (message "Waiting for subprocess to be ready")
+ ;; (message "Subprocess is ready")
+ (interrupt-process proc)
+ (while (prog1 (memq (process-status proc) '(run))
+ (accept-process-output proc 1.0))
+ ) ;; (message "Waiting for subprocess to exit")
+ (goto-char (point-min))
+ (should (re-search-forward exit-msg nil t)))))
+
;;; Tests for `read-key-sequence' code paths.
;;;; Helpers