问题
When I press C-x b
(ido-switch-buffer
) I get a lot of buffers that I don't want to see. I'd like to clear the buffer history.
I tried evaluating this expression (using M-x eval-buffer
):
(setq ido-buffer-history '())
And it took effect; I can tell because I looked at the variable with C-h v ido-buffer-history
. However, the change did not get reflected in the minibuffer when I press C-x b
.
What else should I do? Are there other variables I should be clearing?
UPDATE : The 'extra' buffers that I'm seeing are not active. Interestingly, C-x C-b
(ido-fallback-command
) shows exactly what I would expect. It is the buffer history that I'm interested in. (See the buffer-name-history
and ido-buffer-history
variables for more context.)
Note: Perhaps it will help to mention that I'm using the emacs-starter-kit which has ido-ubiquitous
installed.
回答1:
Add the following to your init.el: (setq ido-use-virtual-buffers nil)
For posterity:
Those are all the active buffers in your session. You can clean them with the following commands:
M-x clean-buffer-list
will close any clean buffers you haven't used in a whileM-x kill-some-buffers
will visit each buffer and ask if you want to close itM-x kill-matching-buffers
will prompt for a regex over buffer names, which you can just leave blank
Edit:
There's also the boring old buffer menu you get with C-x C-b
. In this menu, you can hold d
until it marks each buffer for deletion, then press x
to commit.
回答2:
Thanks to Chris, I learned about ido's virtual buffers. I don't want to disable ido-use-virtual-buffers
altogether. I want to clear the history as needed; these commands accomplish that goal:
(setq ido-virtual-buffers '())
(setq recentf-list '())
(Note that clearing ido-virtual-buffers
was not sufficient -- recentf-list
also must be cleared.)
回答3:
I found this entry on emacswiki.
The variable that stores the buffer history you are referring to is buffer-name-history
If you run M-x describe-variable RET buffer-name-history RET
you will see all of the dead buffers that no longer really exist. The wiki recommends creating a hook that removes the buffer name from the list whenever you kill a buffer.
I just did: M-x eval-expression RET (setq buffer-name-history '()) RET
This seems to have worked. The next time I ran C-x b I only cycled-through my real buffers.
That said, setting the variable to nil seems to completely disable the functionality (the variable doesn't seem to be re-populated once I open more buffers).
来源:https://stackoverflow.com/questions/14151777/how-to-clear-the-emacs-buffer-history