bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#70949: display-buffer-choose-some-window


From: Juri Linkov
Subject: bug#70949: display-buffer-choose-some-window
Date: Wed, 15 May 2024 19:49:28 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

>> +(defcustom display-buffer-choose-some-window 'lru
>> +  "How to choose an existing window.
>> +This defines a strategy of choosing some window
>> +by `display-buffer-use-some-window'.
>> +
>> +The possible choices are `lru' (the default) to select the least recently
>> +used window on that frame, and `mru' to select the most recently used
>> +window on that frame.  When a function, it takes two arguments: a buffer
>> +and an alist, and should return the window where to display the buffer."
>
> I'd call the option 'display-buffer-use-some-window-method' so it's more
> clear that it pertains to 'display-buffer-use-some-window'.  As for the
> first line of the doc-string I'd write
>
> "Which window `display-buffer-use-some-window' should choose."

Ok, done in this patch.

> Also, we should mention the constraints used for 'lru' and that 'mru'
> avoids the selected window here.

Sorry, I don't understand what constraints.  The docstring of
'display-buffer-use-some-window' doesn't mention any 'lru' constraints.

diff --git a/lisp/window.el b/lisp/window.el
index 3935908fdb4..01c8429500d 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -8726,6 +8726,20 @@ display-buffer--lru-window
              (setq best-window window))))))
     (or best-window second-best-window)))
 
+(defcustom display-buffer-use-some-window-method 'lru
+  "Which window `display-buffer-use-some-window' should choose.
+The possible choices are `lru' (the default) to select the least
+recently used window, and `mru' to select the most recently used
+window (not taking into account the selected window).  When a function,
+it takes two arguments: a buffer and an alist, and should return the
+window where to display the buffer."
+  :type '(choice (const :tag "Least recently used" lru)
+                 (const :tag "Most recently used" mru)
+                 (function :tag "Custom function"))
+  :group 'windows
+  :group 'frames
+  :version "30.1")
+
 (defun display-buffer-use-some-window (buffer alist)
   "Display BUFFER in an existing window.
 Search for a usable window, set that window to the buffer, and
@@ -8748,11 +8762,17 @@ display-buffer-use-some-window
                    (window--frame-usable-p (last-nonminibuffer-frame))))
         (window
          ;; Reuse an existing window.
-         (or (display-buffer--lru-window
-               ;; If ALIST specifies 'lru-frames' or 'window-min-width'
-               ;; let them prevail.
-               (append alist `((lru-frames . ,frame)
-                               (window-min-width . full-width))))
+         (or (cond
+               ((eq display-buffer-use-some-window-method 'lru)
+                (display-buffer--lru-window
+                 ;; If ALIST specifies 'lru-frames' or 'window-min-width'
+                 ;; let them prevail.
+                 (append alist `((lru-frames . ,frame)
+                                 (window-min-width . full-width)))))
+               ((eq display-buffer-use-some-window-method 'mru)
+                (get-mru-window t t t))
+               ((functionp display-buffer-use-some-window-method)
+                (funcall display-buffer-use-some-window-method buffer alist)))
              (let ((window (get-buffer-window buffer 'visible)))
                (unless (and not-this-window
                             (eq window (selected-window)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]