简体   繁体   English

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

[英]Emacs - Open buffer list without replacing another buffer

I have one frame, one window. 我有一个框架,一个窗口。 I use Cx 3, I now have two windows. 我使用Cx 3,我现在有两个窗口。

I use Cx Cb in order to see the list of buffers, however it opens it in another window but doesn't put the focus on it. 我使用Cx Cb来查看缓冲区列表,但是它会在另一个窗口中打开它,但不会将焦点放在它上面。 It is even more annoying if I had opened a buffer on the 2nd window. 如果我在第二个窗口打开一个缓冲区,那就更烦人了。

I would prefer to either open the buffer list in the window which currently has the focus, or temporarily change the focus to the buffer list. 我更愿意在当前具有焦点的窗口中打开缓冲区列表,或者暂时将焦点更改为缓冲区列表。

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. 首先,我想首先说ibuffer函数与你想要的ibuffer ,并且在当前窗口中这样做,它绝对值得一试。

Now onto your actual question. 现在谈谈你的实际问题。 Cx Cb by default calls the function list-buffers . Cx Cb默认调用函数list-buffers If you search for that command using Ch 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 . 如果使用Ch f搜索该命令,它将显示文档,从那里您可以通过单击buff-menu.el的带下划线的文本来查看该函数的源代码。

Now we can view the source of the list-buffers , the first function called is display-buffer . 现在我们可以查看list-buffers的来源,第一个被调用的函数是display-buffer That sounds promising. 听起来很有希望。 We can now use Ch f once again to search for the display-buffer command. 我们现在可以再次使用Ch f来搜索display-buffer命令。 Reading though this documentation we see that the variable display-buffer-alist dictates how the display-buffer and in turn how list-buffers works. 通过本文档阅读,我们看到变量display-buffer-alist指示了display-buffer ,以及list-buffers工作方式。 We can then see that by adding ("*Buffer List*" . display-buffer-same-window) to display-buffer-alist you will get the desired result. 然后我们可以通过向display-buffer-alist添加("*Buffer List*" . display-buffer-same-window)来获得所需的结果。

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. 总而言之,您只需在init文件中(add-to-list 'display-buffer-alist '("*Buffer List*" . display-buffer-same-window))进行更改。

Please just try one of these: 请尝试以下方法之一:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM