From b7adb3930de7cc422b2beee61cb20285a3916571 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Tue, 27 Sep 2016 20:47:23 +0200 Subject: [PATCH] Make querying to kill processes customizable Introduce a new customization option, `confirm-kill-processes', that users can set to nil if they don't want Emacs to nag them about killing processes. * lisp/files.el (confirm-kill-processes): New customization option. (save-buffers-kill-emacs): Use customization option. * test/lisp/files-tests.el (files-test--save-buffers-kill-emacs--confirm-kill-processes): Add test for new customization option. --- lisp/files.el | 14 +++++++++++++- test/lisp/files-tests.el | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index 4bd708d..f481b99 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6757,11 +6757,22 @@ confirm-kill-emacs :group 'convenience :version "21.1") +(defcustom confirm-kill-processes t + "Non-nil if Emacs should confirm killing processes on exit. +If this variable is nil, the value of +`process-query-on-exit-flag' is ignored. Otherwise, if there are +processes with a non-nil `process-query-on-exit-flag', Emacs will +prompt the user before killing them." + :type 'boolean + :group 'convenience + :version "26.1") + (defun save-buffers-kill-emacs (&optional arg) "Offer to save each buffer, then kill this Emacs process. With prefix ARG, silently save all file-visiting buffers without asking. If there are active processes where `process-query-on-exit-flag' -returns non-nil, asks whether processes should be killed. +returns non-nil and `confirm-kill-processes' is non-nil, +asks whether processes should be killed. Runs the members of `kill-emacs-query-functions' in turn and stops if any returns nil. If `confirm-kill-emacs' is non-nil, calls it." (interactive "P") @@ -6776,6 +6787,7 @@ save-buffers-kill-emacs (yes-or-no-p "Modified buffers exist; exit anyway? "))) (or (not (fboundp 'process-list)) ;; process-list is not defined on MSDOS. + (not confirm-kill-processes) (let ((processes (process-list)) active) (while processes diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 479848a..581c8bf 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -197,5 +197,24 @@ files-test-bug-18141-file (setenv "FOO" foo-env) (setenv "BAR" bar-env)))) +(ert-deftest files-test--save-buffers-kill-emacs--confirm-kill-processes () + "Test that `save-buffers-kill-emacs' honors +`confirm-kill-processes'." + (cl-letf* ((yes-or-no-p-prompts nil) + ((symbol-function #'yes-or-no-p) + (lambda (prompt) + (push prompt yes-or-no-p-prompts) + nil)) + (kill-emacs-args nil) + ((symbol-function #'kill-emacs) + (lambda (&optional arg) (push arg kill-emacs-args))) + (process (make-process :name "sleep" + :command '("/bin/sleep" "1000"))) + (confirm-kill-processes nil)) + (save-buffers-kill-emacs) + (kill-process process) + (should-not yes-or-no-p-prompts) + (should (equal kill-emacs-args '(nil))))) + (provide 'files-tests) ;;; files-tests.el ends here -- 2.10.0