我知道Emacs试图成为知识分子并根据窗口的哪个维度更大来打开辅助缓冲区,因此如果当前宽度大于高度,它可能出现在垂直分割窗口中,否则会出现在水平分割中。
但我更喜欢它总是在水平分割中打开该列表,因为当缓冲区处于垂直分割时,我看不到长路径。我怎么能这样做?
答案 0 :(得分:5)
我相信你已经将水平/垂直分割术语放回到前面(我永远不会记得哪个是哪个),但是你的目标是保留原始窗口的宽度,我m强迫垂直分裂。
参见 C-h f split-window-sensibly
RET 。它告诉你该怎么做:
You can enforce this function to not split WINDOW horizontally,
by setting (or binding) the variable `split-width-threshold' to
nil. If, in addition, you set `split-height-threshold' to zero,
chances increase that this function does split WINDOW vertically.
作为永久性设置:
(setq split-width-threshold nil)
(setq split-height-threshold 0)
对于特定功能,您可以建议该功能(但请参阅下面的编辑2 ):
(defadvice list-buffers (around list-buffers-split-vertically)
"Always split vertically when displaying the buffer list.
See `split-window-sensibly'."
(let ((split-width-threshold nil)
(split-height-threshold 0))
ad-do-it))
(ad-activate 'list-buffers)
编辑:实际上,在这个例子中,我怀疑你只关心交互式案例,在这种情况下,最好定义一个函数并重新映射绑定:
(defun my-list-buffers-vertical-split ()
"`list-buffers', but forcing a vertical split.
See `split-window-sensibly'."
(interactive)
(let ((split-width-threshold nil)
(split-height-threshold 0))
(call-interactively 'list-buffers)))
(global-set-key [remap list-buffers] 'my-list-buffers-vertical-split)
编辑2: Stefan指出display-buffer-alist
在没有建议功能的情况下促进了这些事情(当然,避免不必要的建议总是一件好事)。我相信我们仍然需要自定义操作,所以:
(defun my-display-buffer-pop-up-same-width-window (buffer alist)
"A `display-buffer' ACTION forcing a vertical window split.
See `split-window-sensibly' and `display-buffer-pop-up-window'."
(let ((split-width-threshold nil)
(split-height-threshold 0))
(display-buffer-pop-up-window buffer alist)))
(add-to-list 'display-buffer-alist
'("\\*Buffer List\\*" my-display-buffer-pop-up-same-width-window))
答案 1 :(得分:0)
如果您不希望在显示窗口后选择窗口,则可以删除(5) - 即删除(select-window (get-buffer-window (buffer-name buffer)))
。我喜欢为3个月的日历保留底部窗口,这就是为什么我有条件使用上面的窗口(如果它存在) - 如果你这么倾向你可以删除那个条件。实际上,这是你的功能,所以你可以根据自己的需要修改一切,看看它是如何工作的。如果你想控制目标窗口的某些方面,那么alist就会像这样使用'((window-width . 33))
。我发现自己总是回到这个文档页面,因为它是我发现的唯一一个很少的正式例子。 。 。当然,来源本身window.el
:http://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Action-Functions.html
(defun lawlist-list-buffers-left (&optional arg)
"Display a list of existing buffers.
The list is displayed in a buffer named \"*Buffer List*\".
See `buffer-menu' for a description of the Buffer Menu.
By default, all buffers are listed except those whose names start
with a space (which are for internal use). With prefix argument
ARG, show only buffers that are visiting files."
(interactive "P")
(lawlist-display-buffer-left (list-buffers-noselect arg) nil))
(defun lawlist-list-buffers-right (&optional arg)
"Display a list of existing buffers.
The list is displayed in a buffer named \"*Buffer List*\".
See `buffer-menu' for a description of the Buffer Menu.
By default, all buffers are listed except those whose names start
with a space (which are for internal use). With prefix argument
ARG, show only buffers that are visiting files."
(interactive "P")
(lawlist-display-buffer-right (list-buffers-noselect arg) nil))
(defun lawlist-display-buffer-left (buffer alist)
"(1) If `buffer` is already displayed, then display it again in the same window.
(2) If `buffer` is not already displayed, and if there is a window to the left,
then display that `buffer` in said window. (3) If `buffer` is not already
displayed, and if there is a window to the right, then use the selected window.
(4) If all else fails, then create a new window to the left and display `buffer` there.
(5) Select the target window which displays `buffer`."
(let (
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction 'above))
((window-in-direction 'left))
((window-in-direction 'right)
(selected-window))
(t
(split-window (selected-window) nil 'left)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
;; OPTIONAL -- uncomment to select the target window.
;; (select-window (get-buffer-window (buffer-name buffer)))
))
(defun lawlist-display-buffer-right (buffer alist)
"(1) If `buffer` is already displayed, then display it again in the same window.
(2) If `buffer` is not already displayed, and if there is a window to the right,
then display that `buffer` in said window. (3) If `buffer` is not already
displayed, and if there is a window to the left, then use the selected window.
(4) If all else fails, then create a new window to the right and display `buffer` there.
(5) Select the target window which displays `buffer`."
(let (
(window
(cond
((get-buffer-window buffer (selected-frame)))
((window-in-direction 'above))
((window-in-direction 'right))
((window-in-direction 'left)
(selected-window))
(t
(split-window (selected-window) nil 'right)))))
(window--display-buffer buffer window 'window alist display-buffer-mark-dedicated)
;; OPTIONAL -- uncomment to select the target window.
;; (select-window (get-buffer-window (buffer-name buffer)))
))
答案 2 :(得分:0)
如果水平或垂直,目前split-height-threshold
和split-width-threshold
似乎都不可能WRT到预期的分裂。这看起来像一个bug,resp。设计问题。
作为一种解决方案M-x split-window-horizontally
呼吁。 -vertically
之前,或使用它向函数提出建议。