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.
This commit is contained in:
Lars Ingebrigtsen 2021-01-07 16:35:48 +01:00
parent 0e6b74d204
commit 40a0f8a3a2
4 changed files with 41 additions and 0 deletions

View 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

View file

@ -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.

View 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

View 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;
}
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);