36
votes

In spite of all the advice that it is a bad idea, I still would like Emacs to stop asking me "Active processes exist; kill them and exit anyway" when I hit C-c C-x. I would like it to simply kill all active processes without asking.

How can I accomplish this?

5
What is the advice that it is a bad idea?Sam Brightman

5 Answers

24
votes

This snippet (goes into your .emacs customization file) will temporarily make Emacs believes that there is no active process when you kill it, and therefore you won't get the annoying prompt.

(require 'cl-lib)
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
  "Prevent annoying \"Active processes exist\" query when you quit Emacs."
  (cl-letf (((symbol-function #'process-list) (lambda ())))
    ad-do-it))
20
votes

You can accomplish this by setting query-on-exit flag for each process to nil. You can use a hook to do this automatically when executing a command interpreter:

(add-hook 'comint-exec-hook 
      (lambda () (set-process-query-on-exit-flag (get-buffer-process (current-buffer)) nil)))
11
votes

The next version of Emacs (25.3 or 26.1) will have a new customization option confirm-kill-processes to make this simpler. You can then say M-x customize-variable RET confirm-kill-processes RET and set the variable to nil to suppress the confirmation prompt.

1
votes

You can't without hacking. If you are feeling adventurous, replace definition of save-buffers-kill-emacs in your .emacs so that it doesn't ask (but don't forget to repeat procedure each time you upgrade Emacs afterwards). Standard defition of that function asks without any ways to customize that behavior.

EDIT:

Alternatively, you could redefine yes-or-no-p like this (untested):

(defadvice yes-or-no-p (around hack-exit (prompt))
   (if (string= prompt "Active processes exist; kill them and exit anyway? ")
       t
      ad-do-it))
1
votes
(if (get-buffer your-process-buffer)
      (progn
    (if (get-buffer-process your-process-buffer)
        (set-process-query-on-exit-flag (get-buffer-process your-process-buffer) nil)
      (kill-buffer your-process-buffer))))