diff options
| author | Lars Ingebrigtsen | 2021-01-07 16:35:48 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-01-07 16:35:48 +0100 |
| commit | 40a0f8a3a2ac790bb398c321e7eb6928da330511 (patch) | |
| tree | f3afec5a6136ff483ca3c6e7e1427b2c2757eb6d | |
| parent | 0e6b74d2047452bb1fc3285921465132aeda0cb7 (diff) | |
| download | emacs-40a0f8a3a2ac790bb398c321e7eb6928da330511.tar.gz emacs-40a0f8a3a2ac790bb398c321e7eb6928da330511.zip | |
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.
| -rw-r--r-- | doc/lispref/windows.texi | 6 | ||||
| -rw-r--r-- | etc/NEWS | 9 | ||||
| -rw-r--r-- | lisp/window.el | 13 | ||||
| -rw-r--r-- | src/window.c | 13 |
4 files changed, 41 insertions, 0 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index b0906acbad5..f305d1a8ee8 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 | |||
| 2634 | windows are dedicated to other buffers (@pxref{Dedicated Windows}). | 2634 | windows are dedicated to other buffers (@pxref{Dedicated Windows}). |
| 2635 | @end defun | 2635 | @end defun |
| 2636 | 2636 | ||
| 2637 | @defun display-buffer-use-least-recent-window buffer alist | ||
| 2638 | This function is like @code{display-buffer-use-some-window}, but will | ||
| 2639 | not reuse the current window, and will use the least recently | ||
| 2640 | switched-to window. | ||
| 2641 | @end defun | ||
| 2642 | |||
| 2637 | @defun display-buffer-in-direction buffer alist | 2643 | @defun display-buffer-in-direction buffer alist |
| 2638 | This function tries to display @var{buffer} at a location specified by | 2644 | This function tries to display @var{buffer} at a location specified by |
| 2639 | @var{alist}. For this purpose, @var{alist} should contain a | 2645 | @var{alist}. For this purpose, @var{alist} should contain a |
| @@ -373,6 +373,15 @@ disabled entirely. | |||
| 373 | 373 | ||
| 374 | ** Windows | 374 | ** Windows |
| 375 | 375 | ||
| 376 | +++ | ||
| 377 | *** New 'display-buffer' function 'display-buffer-use-least-recent-window' | ||
| 378 | This is like 'display-buffer-use-some-window', but won't reuse the | ||
| 379 | current window, and when called repeatedly will try not to reuse a | ||
| 380 | previously selected window. | ||
| 381 | |||
| 382 | *** New function 'window-bump-use-time'. | ||
| 383 | This updates the use time of a window. | ||
| 384 | |||
| 376 | *** The key prefix 'C-x 4 1' displays next command buffer in the same window. | 385 | *** The key prefix 'C-x 4 1' displays next command buffer in the same window. |
| 377 | It's bound to the command 'same-window-prefix' that requests the buffer | 386 | It's bound to the command 'same-window-prefix' that requests the buffer |
| 378 | of the next command to be displayed in the same window. | 387 | of the next command to be displayed in the same window. |
diff --git a/lisp/window.el b/lisp/window.el index c54a0db211e..37e1800ad11 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 | |||
| 7243 | (const display-buffer-below-selected) | 7243 | (const display-buffer-below-selected) |
| 7244 | (const display-buffer-at-bottom) | 7244 | (const display-buffer-at-bottom) |
| 7245 | (const display-buffer-in-previous-window) | 7245 | (const display-buffer-in-previous-window) |
| 7246 | (const display-buffer-use-least-recent-window) | ||
| 7246 | (const display-buffer-use-some-window) | 7247 | (const display-buffer-use-some-window) |
| 7247 | (const display-buffer-use-some-frame) | 7248 | (const display-buffer-use-some-frame) |
| 7248 | (function :tag "Other function")) | 7249 | (function :tag "Other function")) |
| @@ -7387,6 +7388,8 @@ to a list containing one of these \"action\" functions: | |||
| 7387 | `display-buffer-in-previous-window' -- Use a window that did | 7388 | `display-buffer-in-previous-window' -- Use a window that did |
| 7388 | show the buffer before. | 7389 | show the buffer before. |
| 7389 | `display-buffer-use-some-window' -- Use some existing window. | 7390 | `display-buffer-use-some-window' -- Use some existing window. |
| 7391 | `display-buffer-use-least-recent-window' -- Try to avoid re-using | ||
| 7392 | windows that have recently been switched to. | ||
| 7390 | `display-buffer-pop-up-window' -- Pop up a new window. | 7393 | `display-buffer-pop-up-window' -- Pop up a new window. |
| 7391 | `display-buffer-below-selected' -- Use or pop up a window below | 7394 | `display-buffer-below-selected' -- Use or pop up a window below |
| 7392 | the selected one. | 7395 | the selected one. |
| @@ -8256,6 +8259,16 @@ indirectly called by the latter." | |||
| 8256 | (when (setq window (or best-window second-best-window)) | 8259 | (when (setq window (or best-window second-best-window)) |
| 8257 | (window--display-buffer buffer window 'reuse alist)))) | 8260 | (window--display-buffer buffer window 'reuse alist)))) |
| 8258 | 8261 | ||
| 8262 | (defun display-buffer-use-least-recent-window (buffer alist) | ||
| 8263 | "Display BUFFER in an existing window, but that hasn't been used lately. | ||
| 8264 | This `display-buffer' action function is like | ||
| 8265 | `display-buffer-use-some-window', but will cycle through windows | ||
| 8266 | when displaying buffers repeatedly, and if there's only a single | ||
| 8267 | window, it will split the window." | ||
| 8268 | (when-let ((window (display-buffer-use-some-window | ||
| 8269 | buffer (cons (cons 'inhibit-same-window t) alist)))) | ||
| 8270 | (window-bump-use-time window))) | ||
| 8271 | |||
| 8259 | (defun display-buffer-use-some-window (buffer alist) | 8272 | (defun display-buffer-use-some-window (buffer alist) |
| 8260 | "Display BUFFER in an existing window. | 8273 | "Display BUFFER in an existing window. |
| 8261 | Search for a usable window, set that window to the buffer, and | 8274 | Search for a usable window, set that window to the buffer, and |
diff --git a/src/window.c b/src/window.c index 58204c13e44..5e78aa400b5 100644 --- a/src/window.c +++ b/src/window.c | |||
| @@ -8100,6 +8100,18 @@ and scrolling positions. */) | |||
| 8100 | return Qt; | 8100 | return Qt; |
| 8101 | return Qnil; | 8101 | return Qnil; |
| 8102 | } | 8102 | } |
| 8103 | |||
| 8104 | DEFUN ("window-bump-use-time", Fwindow_bump_use_time, | ||
| 8105 | Swindow_bump_use_time, 1, 1, 0, | ||
| 8106 | doc: /* Mark WINDOW as having been recently used. */) | ||
| 8107 | (Lisp_Object window) | ||
| 8108 | { | ||
| 8109 | struct window *w = decode_valid_window (window); | ||
| 8110 | |||
| 8111 | w->use_time = ++window_select_count; | ||
| 8112 | return Qnil; | ||
| 8113 | } | ||
| 8114 | |||
| 8103 | 8115 | ||
| 8104 | 8116 | ||
| 8105 | static void init_window_once_for_pdumper (void); | 8117 | static void init_window_once_for_pdumper (void); |
| @@ -8573,6 +8585,7 @@ displayed after a scrolling operation to be somewhat inaccurate. */); | |||
| 8573 | defsubr (&Swindow_vscroll); | 8585 | defsubr (&Swindow_vscroll); |
| 8574 | defsubr (&Sset_window_vscroll); | 8586 | defsubr (&Sset_window_vscroll); |
| 8575 | defsubr (&Scompare_window_configurations); | 8587 | defsubr (&Scompare_window_configurations); |
| 8588 | defsubr (&Swindow_bump_use_time); | ||
| 8576 | defsubr (&Swindow_list); | 8589 | defsubr (&Swindow_list); |
| 8577 | defsubr (&Swindow_list_1); | 8590 | defsubr (&Swindow_list_1); |
| 8578 | defsubr (&Swindow_prev_buffers); | 8591 | defsubr (&Swindow_prev_buffers); |