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?

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52

5 Answers5

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.

YoungFrog
  • 3,496
  • 15
  • 27
  • 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 Aug 24 '16 at 10:32
  • @user905686 That's a question asked by `save-buffers-kill-emacs` and unrelated to killing the buffers. – YoungFrog Aug 24 '16 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](http://emacs.stackexchange.com/q/26565/13091). – user905686 Aug 25 '16 at 09:43
8

Or the simpler one would be :

(setq kill-buffer-query-functions nil)

Inspired from abo-abo config

azzamsa
  • 634
  • 7
  • 16
  • 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 Feb 17 '22 at 02:42
3

This will not affect the global variable scope

(let ((kill-buffer-query-functions nil))
  (kill-buffer "*Python*"))
Talespin_Kit
  • 435
  • 2
  • 11
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.

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