gpt4 book ai didi

emacs - Emacs 中显示缓冲区 split-height-threshold 和 split-width-threshold 的反向求值顺序

转载 作者:行者123 更新时间:2023-12-03 22:48:16 28 4
gpt4 key购买 nike

display-buffer必须在现有 Pane 中创建一个新窗口,Emacs manual声明 split-height-threshold首先查看新窗口是否可以低于当前窗口,然后 split-width-threshold对于并排窗口以相同的方式进行评估。

如果宽度足够高,有没有办法让Emacs首先尝试将窗口并排放置?我可以设置split-height-thresholdnil完全禁止垂直拆分,但是如果当前窗口不够宽,这会使 Emacs 窃取另一个窗口。

最佳答案

您可以通过自定义变量 split-window-preferred-function 来让 Emacs 做到这一点。 :

(defun my-split-window-sensibly (&optional window)
(let ((window (or window (selected-window))))
(or (and (window-splittable-p window t)
;; Split window horizontally.
(with-selected-window window
(split-window-right)))
(and (window-splittable-p window)
;; Split window vertically.
(with-selected-window window
(split-window-below)))
(and (eq window (frame-root-window (window-frame window)))
(not (window-minibuffer-p window))
;; If WINDOW is the only window on its frame and is not the
;; minibuffer window, try to split it horizontally disregarding
;; the value of `split-width-threshold'.
(let ((split-width-threshold 0))
(when (window-splittable-p window t)
(with-selected-window window
(split-window-right))))))))

(setq split-window-preferred-function 'my-split-window-sensibly)

变量 split-window-preferred-function

specifies a function for splitting a window, in order to make a new window for displaying a buffer. It is used by the display-buffer-pop-up-window action function to actually split the window.



默认情况下,它设置为 split-window-sensibly .我上面提供的功能是 split-window-sensibly的修改版(在 window.el 中定义)它只是颠倒了原始函数的步骤,导致 Emacs “更喜欢”并排窗口拆分而不是堆叠窗口拆分。

关于emacs - Emacs 中显示缓冲区 split-height-threshold 和 split-width-threshold 的反向求值顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23659909/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com