Emacs - 打开缓冲区列表而不替换另一个缓冲区

时间:2016-04-04 13:08:37

标签: emacs buffer

我有一个框架,一个窗口。 我使用Cx 3,现在有两个窗口。

我使用Cx Cb来查看缓冲区列表,但是它会在另一个窗口中打开它,但不会把重点放在它上面。如果我在第二个窗口打开一个缓冲区,那就更烦人了。

我更喜欢在当前具有焦点的窗口中打开缓冲区列表,或者暂时将焦点更改为缓冲区列表。

2 个答案:

答案 0 :(得分:3)

First of all I want to start by saying that the ibuffer function does similary to what you want and does so in the current window, its definitely worth checking out.

Now onto your actual question. C-x C-b by default calls the function list-buffers. If you search for that command using C-h f it will show you the documentation, from there you can view the source code for the function by clicking on the underlined text that says buff-menu.el.

Now we can view the source of the list-buffers, the first function called is display-buffer. That sounds promising. We can now use C-h f once again to search for the display-buffer command. Reading though this documentation we see that the variable display-buffer-alist dictates how the display-buffer and in turn how list-buffers works. We can then see that by adding ("*Buffer List*" . display-buffer-same-window) to display-buffer-alist you will get the desired result.

All in all you simply need to put (add-to-list 'display-buffer-alist '("*Buffer List*" . display-buffer-same-window)) in your init file for your changes to take place.

答案 1 :(得分:0)

请尝试以下其中一项:

  1. 打开当前具有焦点的缓冲区列表:
  2. (defun my:list-buffers (&optional arg)
      (interactive "P")
      (display-buffer (list-buffers-no-select arg) '(display-buffer-same-window)))
    
    1. 改变焦点
    2. (defun my:list-buffers2 (&optional arg)
        (interactive "P")
        (select-window (list-buffers arg)))