36

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?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Adam
  • 1,409
  • 12
  • 19

6 Answers6

24

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))
Philipp
  • 48,066
  • 12
  • 84
  • 109
polyglot
  • 9,945
  • 10
  • 49
  • 63
  • Doesn't work for me. Specs: Aquamacs 23.2.50.1 / Aquamacs-SLIME-2010-11-14 / Mac OS X 10.6.4 / MacBook Pro 5,1 – mcandre Nov 16 '10 at 00:26
  • 2
    `flet` is really cool but unfortunately deprecated since Emacs 24.3, however Nic Ferrier has reimplemented it as `noflet` which is available through package.el. Probably best to either use that instead, or use the other solution below with hooks (on second thought, defadvice is a bit ugly to begin with, so the hooks solution is probably better generally). – robru Dec 30 '14 at 08:41
  • I've updated this answer to use `cl-letf`, which should work with `cl-lib` and lexical binding. – Philipp Sep 27 '16 at 17:34
  • In my case, I worked with GNU Emacs 26.3 on Ubuntu 16.04.7 LTS. – Keiku Dec 20 '20 at 12:22
  • Worked perfectly for Emacs 27.1 on Debian Testing. Many thanks! – Marco Craveiro Sep 23 '21 at 20:16
19

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)))
Ian Kelling
  • 9,643
  • 9
  • 35
  • 39
Jürgen Hötzel
  • 18,997
  • 3
  • 42
  • 58
  • 4
    Note that the docs say (regarding process-kill-without-query) "This function is obsolete since 22.1" and recommend using set-process-query-on-exit-flag instead. – Sean Apr 27 '10 at 17:37
  • 1
    For some reason this didn't work for me with `comint-exec-hook`, using `multi-term` (the hook simply never ran). Had to switch it to `term-exec-hook` and that worked. – robru Dec 30 '14 at 08:52
13

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.

Philipp
  • 48,066
  • 12
  • 84
  • 109
1
(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))))
yPhil
  • 8,049
  • 4
  • 57
  • 83
1

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))
mcandre
  • 22,868
  • 20
  • 88
  • 147
1

Here's what I feel is a better solution that specifically ignores only SLIME buffers:

(defun process-ignore-on-exit (regexp)
  (cl-loop for proc in (process-list)
           when (s-matches-p regexp (process-name proc))
           do
           (progn (message "disabling query-on-exit for '%s'" proc)
                  (set-process-query-on-exit-flag proc nil))))

(defun slime-ignore-processes-on-exit (&rest r)
  (process-ignore-on-exit "SLIME"))

(advice-add #'save-some-buffers :before #'slime-ignore-processes-on-exit)
ealfonso
  • 6,622
  • 5
  • 39
  • 67
  • Nice solution but I had to call `save-some-buffers` manually to see an effect. I substituted it with `save-buffers-kill-terminal`, which is bound to `C-x C-c`. Is there any downside to this? – Torsten Bronger Aug 18 '23 at 06:25
  • I'm not sure how you were previously exiting emacs, but that is how I normally exit emacs, by typing `C-x C-c` which is bound to `save-buffers-kill-terminal`. This internally calls `save-some-buffers` (`save-buffers-kill-terminal -> save-buffers-kill-emacs -> save-some-buffers`) which will trigger the advice. – ealfonso Aug 18 '23 at 15:34