[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 3c82e96954 2/2: Add new user option display-buffer-avoid-small-wi
From: |
Lars Ingebrigtsen |
Subject: |
master 3c82e96954 2/2: Add new user option display-buffer-avoid-small-windows |
Date: |
Fri, 20 May 2022 06:05:50 -0400 (EDT) |
branch: master
commit 3c82e96954450e766c63b507ed4e927d18e4cd9c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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.
---
doc/lispref/windows.texi | 5 +++++
etc/NEWS | 4 ++++
lisp/window.el | 23 +++++++++++++++++++----
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 90551e6697..bc3857b136 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 2314e55164..85413b0d38 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 4ad2defdf9..a0c51600dc 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)