emacs-diffs
[Top][All Lists]
Advanced

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

master 40a0f8a: Add a display-buffer window selection function that's mo


From: Lars Ingebrigtsen
Subject: master 40a0f8a: Add a display-buffer window selection function that's more like XEmacs
Date: Thu, 7 Jan 2021 10:36:04 -0500 (EST)

branch: master
commit 40a0f8a3a2ac790bb398c321e7eb6928da330511
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add a display-buffer window selection function that's more like XEmacs
    
    * 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 |  6 ++++++
 etc/NEWS                 |  9 +++++++++
 lisp/window.el           | 13 +++++++++++++
 src/window.c             | 13 +++++++++++++
 4 files changed, 41 insertions(+)

diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index b0906ac..f305d1a 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index 48fb4b8..14d6b45 100644
--- 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.
diff --git a/lisp/window.el b/lisp/window.el
index c54a0db..37e1800 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -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
diff --git a/src/window.c b/src/window.c
index 58204c1..5e78aa4 100644
--- a/src/window.c
+++ b/src/window.c
@@ -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;
+}
+
 
 
 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);



reply via email to

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