[Top][All Lists]

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

Re: eval-print-last-sexp: "Selecting deleted buffer" error when the curr

From: Matthew White
Subject: Re: eval-print-last-sexp: "Selecting deleted buffer" error when the current buffer is killed evaluating the expression
Date: Fri, 30 Jul 2021 16:07:53 +0200

On Fri, 30 Jul 2021 08:58:34 +0300
Eli Zaretskii <eliz@gnu.org> wrote:

> > Date: Fri, 30 Jul 2021 00:55:51 +0200
> > From: Matthew White <mehw.is.me@inventati.org>
> > 
> > I tumbled on the error in the subject, "Selecting deleted buffer",
> > evaluating the following line in the "*scratch*" buffer with C-j:
> > 
> > (kill-buffer (current-buffer))
> > 
> > When the other buffer isn't read-only, suppose "*foo*" is selected
> > after killing the current buffer "*scratch*", the error "Selecting
> > deleted buffer" appears into the echo area and the return value of
> > the evaluation is printed into the other buffer "*foo*".
> > 
> > If the other buffer is "*Messages*", which is read-only, the error
> > "Buffer is read-only: #<buffer *Messages*>" will appear instead.
> > 
> > I'd like to discuss the possibility to enforce printing the output
> > either to the initial current buffer when eval-print-last-sexp has
> > been called, or to the echo area when the prefix '-' is given.  If
> > the initial current buffer (aka standard-output) is killed, during
> > the evaluation of the expression, we fall back to the echo area as
> > the output medium.  
> Could you please tell what are the real-life situations where this
> problem happens and causes trouble?  Killing the current buffer this
> way is unusual, so why isn't what we have now sufficient?  You tried
> to insert something into a killed buffer, Emacs told you it cannot do
> that; why is that a problem?

I understand that such occasions are rare, I mean killing the current
buffer evaluating an expression also in the current buffer like:

(kill-buffer (current-buffer))

eval-print-last-sexp is trying to insert something into a dead buffer,
by calling terpri with standard-output set to the dead buffer.

This could be prevented by checking standard-output:

(when (buffer-live-p standard-output)

Less uncommon than killing the current buffer evaluating an expression
with C-j, is redirecting the output to the echo area with a '-' prefix
C-u - C-j.  I'd expect no output into the current buffer, and the call
to eval-last-sexp respects this, while terpri does not and prints into
the standard-output (aka current buffer at the time C-j was pressed).

There's also the strange behavior of printing to a buffer which is not
the one where the expression was evaluated. This is also rare, happens
when the buffer is killed, like described previously:

;; Always prints to the actual current buffer.
(eval-last-sexp (or eval-last-sexp-arg-internal t))

> IME, trying to "fix" such obscure problems causes problems of its own
> that we then get to rectify for several releases in the future, so the
> net gains are very small if there are any.

I agree, there is a little gain into that.  I just explored the source
of the problems to understand what they are.

IMHO, when C-u - C-j is used terpri shouldn't print to stadard-output,
since the evaluation's return value is destined to the echo area.  And
checking if standard-output is a live buffer is also trivial.

What do you think?


Attachment: pgpok58muXL3f.pgp
Description: OpenPGP digital signature

reply via email to

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