[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: kill-buffer without asking for confirmation
From: |
Tassilo Horn |
Subject: |
Re: kill-buffer without asking for confirmation |
Date: |
Mon, 28 Nov 2022 10:25:46 +0100 |
User-agent: |
mu4e 1.9.3; emacs 29.0.50 |
Peter Münster <pm@a16n.net> writes:
Hi Peter,
> When a buffer is modified, kill-buffer normally asks for confirmation
> ("Buffer modified; kill anyway?"). How can I avoid this confirmation
> please?
>
> This worked with version 28.X:
>
> (defun some-function-called-by-timer ()
> "Send email to user."
> (compose-mail user-mail-address "bla")
> (insert "bla")
> (funcall send-mail-function)
> (cl-letf (((symbol-function 'yes-or-no-p) (lambda (_) t)))
> (kill-buffer)))
>
> But unfortunately, it doesn't work any more with the latest 29.0.50.
Yeah, it's not yes-or-no-query anymore but now you can answer
yes/no/"first save and then kill". You could use your above function
but swap yes-or-no-p with kill-buffer--possibly-save (or temporarily
redefine both to "always t"), I think.
OTOH, the definition of kill-buffer in buffer.c suggests that the query
is only performed when your function is called interactively which
shouldn't be the case when it's run from a timer as its name suggests.
Another way might be to slap a (let ((noninteractive t)) ...) around the
kill-buffer call. Maybe that does the trick, too, and works with more
emacs versions.
Bye,
Tassilo