How to clear the Emacs buffer history?

偶尔善良 提交于 2021-02-07 20:21:04

问题


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 while
  • M-x kill-some-buffers will visit each buffer and ask if you want to close it
  • M-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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!