From: Lars Ingebrigtsen Date: Fri, 20 May 2022 10:05:34 +0000 (+0200) Subject: Add new user option display-buffer-avoid-small-windows X-Git-Tag: emacs-29.0.90~1910^2~562 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3c82e96954450e766c63b507ed4e927d18e4cd9c;p=emacs.git Add new user option display-buffer-avoid-small-windows * doc/lispref/windows.texi (Choosing Window Options): Document it. * lisp/window.el (display-buffer-avoid-small-windows): New user option (bug#10186). (get-lru-window): Use it. --- diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 90551e6697e..bc3857b1366 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -3305,6 +3305,11 @@ window has at least that many columns. If the value is @code{nil}, that means not to split this way. @end defopt +@defopt display-buffer-avoid-small-windows +If non-@code{nil}, this should be a number. Windows that have fewer +lines than this will be avoided when choosing an existing window. +@end defopt + @defopt even-window-sizes This variable, if non-@code{nil}, causes @code{display-buffer} to even window sizes whenever it reuses an existing window, and that window is diff --git a/etc/NEWS b/etc/NEWS index 2314e55164c..85413b0d38d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -605,6 +605,10 @@ specifiers can now use ':type webp'. ** Windows +*** New user option 'display-buffer-avoid-small-windows'. +If non-nil, this should be a window height. If windows smaller than +this will be avoided by 'display-buffer', if possible. + +++ *** New display action 'display-buffer-full-frame'. This action removes other windows on the frame when displaying a diff --git a/lisp/window.el b/lisp/window.el index 4ad2defdf9c..a0c51600dc9 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -2488,8 +2488,15 @@ and no others." (defalias 'some-window 'get-window-with-predicate) +(defcustom display-buffer-avoid-small-windows nil + "If non-nil, windows that have fewer lines than this are avoided. +This is used by `get-lru-window'." + :type '(choice nil number) + :version "29.1" + :group 'windows) + (defun get-lru-window (&optional all-frames dedicated not-selected no-other) - "Return the least recently used window on frames specified by ALL-FRAMES. + "Return the least recently used window on frames specified by ALL-FRAMES. Return a full-width window if possible. A minibuffer window is never a candidate. A dedicated window is never a candidate unless DEDICATED is non-nil, so if all windows are dedicated, the @@ -2513,15 +2520,23 @@ have special meanings: - A frame means consider all windows on that frame only. Any other value of ALL-FRAMES means consider all windows on the -selected frame and no others." - (let (best-window best-time second-best-window second-best-time time) - (dolist (window (window-list-1 nil 'nomini all-frames)) +selected frame and no others. + +`display-buffer-avoid-small-windows' is also taken into +consideration. Windows smaller than this size will be avoided if +there are larger windows available." + (let ((windows (window-list-1 nil 'nomini all-frames)) + best-window best-time second-best-window second-best-time time) + (dolist (window windows) (when (and (or dedicated (not (window-dedicated-p window))) (or (not not-selected) (not (eq window (selected-window)))) (or (not no-other) (not (window-parameter window 'no-other-window)))) (setq time (window-use-time window)) (if (or (eq window (selected-window)) + (and display-buffer-avoid-small-windows + (< (window-height window) + display-buffer-avoid-small-windows)) (not (window-full-width-p window))) (when (or (not second-best-time) (< time second-best-time)) (setq second-best-time time)