Reverse evaluation order of split-height-threshold and split-width-threshold in Emacs for display-buffer

孤者浪人 提交于 2019-12-02 04:08:48

问题


When display-buffer has to create a new window in an existing pane, the Emacs manual states that split-height-threshold is looked at first to determine if the new window can be below the current one, then split-width-threshold is evaluated in the same way for side-by-side windows.

Is there a way to make Emacs try first to put the windows side by side first if the width is high enough? I can set split-height-threshold to nil to inhibit vertical split altogether, but that makes Emacs steal another window if the current one is not wide enough.


回答1:


You can make Emacs do this by customizing the variable split-window-preferred-function:

(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)

The variable 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.

By default, it is set to split-window-sensibly. The function I am providing above is a modified version of split-window-sensibly (defined in window.el) that simply reverses the steps of the original function, causing Emacs to "prefer" side-by-side window splits over stacked ones.



来源:https://stackoverflow.com/questions/23659909/reverse-evaluation-order-of-split-height-threshold-and-split-width-threshold-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!