用于显示缓冲区的Emacs中的分裂高度阈值和分割宽度阈值的反向评估顺序

时间:2014-05-14 16:12:20

标签: emacs emacs24

display-buffer必须在现有窗格中创建新窗口时,Emacs manual会首先查看split-height-threshold以确定新窗口是否低于当前窗口,对于并排窗口,然后 split-width-threshold的评估方式相同。

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

1 个答案:

答案 0 :(得分:2)

您可以通过自定义变量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

  

指定用于分割窗口的函数,以便创建用于显示缓冲区的新窗口。 display-buffer-pop-up-window动作函数使用它来实际拆分窗口。

默认情况下,它设置为split-window-sensibly。我上面提供的函数是split-window-sensibly的修改版本(在window.el中定义),它简单地反转原始函数的步骤,使Emacs“更喜欢”并排堆叠的窗口分割的。