Subject: RE: bug#17048: switch-to-buffer function show killed buffers names

From: Drew Adams <[email-masked]>
Date: Thu, 20 Mar 2014 08:45:31 -0700 (PDT)

> Yes it's history, I think this fix the bug (but only for buffer names)
> 
> (add-hook 'kill-buffer-hook
>           (lambda ()
>             (setq buffer-name-history (delete (buffer-name)
>                                               buffer-name-history))))
> 

Bad idea.  And not a bug.

The history is supposed to be just that: a history of buffer names
that the user has entered as minibuffer input.

That this or that command might use this history for various things
is irrelevant to this.  If a given command has no use for buffer
names that do not correspond to currently live buffers then it is
_up to that command_ to DTRT for its own use.  And not by modifying
the history list but by filtering a copy of it.

IOW, any such filtering should be done, if needed, by the code that
USES the history variable.  It should not be done to the variable
itself, and especially not by some general code such as a kill-buffer
hook.

And in particular, command `switch-to-buffer' should NOT filter out
such buffer names.  Besides the full history being important, _a
priori_, this command is specifically designed to let you create a
new buffer, including a new buffer with the same name as one that
previously existed but has been killed.  Or, as Stefan pointed out,
one that has a similar name (e.g. by editing a history-list entry).

It is trivial for a user to write a command that, for example,
lets her choose only among existing (live) buffers.  And in that
case she can also decide whether she wants the available history
to be filtered similarly.  Nothing wrong with that.

But that is not `switch-to-buffer'.