19

I have C-x C-k bound to kill-this-buffer. But when I enter into a buffer which is running a process like Python or MySQL, if I do C-x C-k it asks

Buffer "*Python*" has a running process; kill it (y or n)?

How can I kill process buffers without confirmation?

5 Answers 5

17

Remove the corresponding function from the relevant variable :

(setq kill-buffer-query-functions (delq 'process-kill-buffer-query-function kill-buffer-query-functions))

How did I find this ?

kill-this-buffer uses kill-buffer internally, which references the variable kill-buffer-query-functions.

3
  • I put this line into my startup file and no errors are shown in the message buffer. When I have a scheme process running (started with run-scheme) when exiting still a dialog pops up and asks "Active processes exist; kill them and exit anyway?".
    – user905686
    Commented Aug 24, 2016 at 10:32
  • @user905686 That's a question asked by save-buffers-kill-emacs and unrelated to killing the buffers.
    – YoungFrog
    Commented Aug 24, 2016 at 11:48
  • Now I see that it works for just killing a buffer. I thought exiting emacs would try to kill the buffers and that therefore the confirmation dialog has the same origin. I asked a new question: Exiting emacs without confirmation to kill running processes.
    – user905686
    Commented Aug 25, 2016 at 9:43
8

Or the simpler one would be :

(setq kill-buffer-query-functions nil)

Inspired from abo-abo config

1
  • 1
    That's making an assumption that kill-buffer-query-functions will contain only process-kill-buffer-query-function. This is true, by default, in current versions; but that's still not a sensible assumption to make.
    – phils
    Commented Feb 17, 2022 at 2:42
4

This will not affect the global variable scope

(let ((kill-buffer-query-functions nil))
  (kill-buffer "*Python*"))
0

The answers here solve the question but for completness I will show my solution based on YoungFrog answer which in my opinion leads to a problematic state where no more confirmation will be asked for any process buffer killing.

Context

I just want to be able to kill *ansi-term-1* buffer with no confirmation :

(defun perso/close-shell ()

  ;; remove confirmation for process buffers
  (setq kill-buffer-query-functions
    (delq 'process-kill-buffer-query-function kill-buffer-query-functions))

  (kill-buffer "*ansi-term-1*")

  ;; confirmation is now active for other process buffer
  (add-to-list 'kill-buffer-query-functions 'process-kill-buffer-query-function))

and revert to the previous state where confirmation is asked for other process buffers.

0
(defun custom-kill-buffer-no-confirm (&optional arg)
  (interactive "P")
  "Kill current buffer unconditionally."
  (set-buffer-modified-p nil)
  (kill-buffer (current-buffer)))

2
  • 1
    Why do you provide a prefix arg but do nothing with it?
    – Drew
    Commented Feb 16, 2022 at 23:14
  • Remove it if you want. I vaguely recall getting incompatible argument type errors so that might be why. Commented Feb 18, 2022 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.