[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-x C-v considered harmful

From: Juri Linkov
Subject: Re: C-x C-v considered harmful
Date: Thu, 09 Jul 2009 02:28:48 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

> I brought these examples to help deciding what a default list of buffers
> should require a confirmation.  As Johan pointed out it is just a matter
> of setting `kill-buffer-query-functions', e.g. in *shell* buffers.
> But note that this can be annoying for users who like creating a lot
> of shell buffers, so exiting from Emacs will ask a separate confirmation
> for each of them.  (BTW, `C-x C-c' already asks a confirmation about
> shell buffers.)

This can be handled by the following code:

(add-hook 'kill-buffer-query-functions 'process-kill-buffer-query-function)

(defun process-kill-buffer-query-function ()
  "Ask before killing a buffer that has an active process."
  (let ((process (get-buffer-process (current-buffer))))
    (or (not process)
        (not (memq (process-status process) '(run stop open listen)))
        (not (process-query-on-exit-flag process))
        (yes-or-no-p "Buffer has an active process; kill it? "))))

It fixes both cases: killing a shell buffer as reported by OP,
and killing a *Async Shell Command* buffer as I reported.

The reason for doing this is the same as why exiting Emacs
with `C-x C-c' asks a question about killing active processes.
Active processes has the same worth to be asked a confirmation
regardless whether they are killed with `C-x k', `C-x C-v' or `C-x C-c'.

The variable `kill-buffer-query-functions' is nil by default,
so maybe it's better to implement this confirmation in Fkill_buffer
instead of the hook `kill-buffer-query-functions'?

Juri Linkov

reply via email to

[Prev in Thread] Current Thread [Next in Thread]