]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a display-buffer window selection function that's more like XEmacs
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 7 Jan 2021 15:35:48 +0000 (16:35 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 7 Jan 2021 15:35:48 +0000 (16:35 +0100)
* doc/lispref/windows.texi (Buffer Display Action Functions):
Document it.
* lisp/window.el (display-buffer--action-function-custom-type): Add.
(display-buffer): Mention it.
(display-buffer-use-least-recent-window): New function (bug#45688).

* src/window.c (Fwindow_bump_use_time): New function.

doc/lispref/windows.texi
etc/NEWS
lisp/window.el
src/window.c

index b0906acbad5744c86d7310d1abe57636c1e01aa9..f305d1a8ee874bf8212a6640f9afdb5805fd5c3f 100644 (file)
@@ -2634,6 +2634,12 @@ window and displaying the buffer in that window.  It can fail if all
 windows are dedicated to other buffers (@pxref{Dedicated Windows}).
 @end defun
 
+@defun display-buffer-use-least-recent-window buffer alist
+This function is like @code{display-buffer-use-some-window}, but will
+not reuse the current window, and will use the least recently
+switched-to window.
+@end defun
+
 @defun display-buffer-in-direction buffer alist
 This function tries to display @var{buffer} at a location specified by
 @var{alist}.  For this purpose, @var{alist} should contain a
index 48fb4b88e15897dc6cdef4b2a096e990bd6227a6..14d6b45c929267cdd60f95096ef470776c4c2dc8 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -373,6 +373,15 @@ disabled entirely.
 
 ** Windows
 
++++
+*** New 'display-buffer' function 'display-buffer-use-least-recent-window'
+This is like 'display-buffer-use-some-window', but won't reuse the
+current window, and when called repeatedly will try not to reuse a
+previously selected window.
+
+*** New function 'window-bump-use-time'.
+This updates the use time of a window.
+
 *** The key prefix 'C-x 4 1' displays next command buffer in the same window.
 It's bound to the command 'same-window-prefix' that requests the buffer
 of the next command to be displayed in the same window.
index c54a0db211e473d3397d74730d48e12ec22ae2e8..37e1800ad115d5737ebf1ddca1b011bd58606980 100644 (file)
@@ -7243,6 +7243,7 @@ The actual non-nil value of this variable will be copied to the
           (const display-buffer-below-selected)
           (const display-buffer-at-bottom)
           (const display-buffer-in-previous-window)
+          (const display-buffer-use-least-recent-window)
           (const display-buffer-use-some-window)
           (const display-buffer-use-some-frame)
           (function :tag "Other function"))
@@ -7387,6 +7388,8 @@ to a list containing one of these \"action\" functions:
  `display-buffer-in-previous-window' -- Use a window that did
     show the buffer before.
  `display-buffer-use-some-window' -- Use some existing window.
+ `display-buffer-use-least-recent-window' -- Try to avoid re-using
+    windows that have recently been switched to.
  `display-buffer-pop-up-window' -- Pop up a new window.
  `display-buffer-below-selected' -- Use or pop up a window below
     the selected one.
@@ -8256,6 +8259,16 @@ indirectly called by the latter."
     (when (setq window (or best-window second-best-window))
       (window--display-buffer buffer window 'reuse alist))))
 
+(defun display-buffer-use-least-recent-window (buffer alist)
+  "Display BUFFER in an existing window, but that hasn't been used lately.
+This `display-buffer' action function is like
+`display-buffer-use-some-window', but will cycle through windows
+when displaying buffers repeatedly, and if there's only a single
+window, it will split the window."
+  (when-let ((window (display-buffer-use-some-window
+                      buffer (cons (cons 'inhibit-same-window t) alist))))
+    (window-bump-use-time window)))
+
 (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
index 58204c13e44ea7d8da0b4f7003651c1df85caf3f..5e78aa400b5172648ad9c98368a4e63e98547ed1 100644 (file)
@@ -8100,6 +8100,18 @@ and scrolling positions.  */)
     return Qt;
   return Qnil;
 }
+
+DEFUN ("window-bump-use-time", Fwindow_bump_use_time,
+       Swindow_bump_use_time, 1, 1, 0,
+       doc: /* Mark WINDOW as having been recently used.  */)
+  (Lisp_Object window)
+{
+  struct window *w = decode_valid_window (window);
+
+  w->use_time = ++window_select_count;
+  return Qnil;
+}
+
 \f
 
 static void init_window_once_for_pdumper (void);
@@ -8573,6 +8585,7 @@ displayed after a scrolling operation to be somewhat inaccurate.  */);
   defsubr (&Swindow_vscroll);
   defsubr (&Sset_window_vscroll);
   defsubr (&Scompare_window_configurations);
+  defsubr (&Swindow_bump_use_time);
   defsubr (&Swindow_list);
   defsubr (&Swindow_list_1);
   defsubr (&Swindow_prev_buffers);