diff options
| author | Juri Linkov | 2024-01-16 18:54:04 +0200 |
|---|---|---|
| committer | Juri Linkov | 2024-01-16 18:54:04 +0200 |
| commit | 6f75d0f36dd44fa794ed264042bb6edb4d897bec (patch) | |
| tree | 625a5e88134d85ecdff2f59708670639983dc32e | |
| parent | 44fcab04f6a346e602f00a6d9f5b0e6f0dbeb5e0 (diff) | |
| download | emacs-6f75d0f36dd44fa794ed264042bb6edb4d897bec.tar.gz emacs-6f75d0f36dd44fa794ed264042bb6edb4d897bec.zip | |
New display action alist entry 'post-command-select-window' (bug#67993)
* doc/lispref/windows.texi (Buffer Display Action Alists):
Add 'post-command-select-window'.
* lisp/window.el (display-buffer): Add 'post-command-select-window'
to the docstring and handle at the end of function.
| -rw-r--r-- | doc/lispref/windows.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/window.el | 19 |
3 files changed, 35 insertions, 0 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 93b25cbe67f..f14e74bc785 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -3344,6 +3344,16 @@ It is called @emph{after} the buffer is displayed, and @emph{before} | |||
| 3344 | the entries @code{window-height}, @code{window-width} and | 3344 | the entries @code{window-height}, @code{window-width} and |
| 3345 | @code{preserve-size} are applied that could resize the window to fit | 3345 | @code{preserve-size} are applied that could resize the window to fit |
| 3346 | it to the inserted contents. | 3346 | it to the inserted contents. |
| 3347 | |||
| 3348 | @vindex post-command-select-window@r{, a buffer display action alist entry} | ||
| 3349 | @item post-command-select-window | ||
| 3350 | If the value is non-@code{nil}, the buffer displayed by @code{display-buffer} | ||
| 3351 | is selected after the current command is executed by running the hook | ||
| 3352 | @code{post-command-hook} (@pxref{Command Overview}). | ||
| 3353 | If the value is @code{nil}, the buffer selected by such functions as | ||
| 3354 | @code{pop-to-buffer} is deselected, and the window that was selected | ||
| 3355 | before calling this function will remain selected regardless of which | ||
| 3356 | windows were selected afterwards within this command. | ||
| 3347 | @end table | 3357 | @end table |
| 3348 | 3358 | ||
| 3349 | By convention, the entries @code{window-height}, @code{window-width} | 3359 | By convention, the entries @code{window-height}, @code{window-width} |
| @@ -262,6 +262,12 @@ Anything following the symbol 'mode-line-format-right-align' in | |||
| 262 | right-aligned to is controlled by the new user option | 262 | right-aligned to is controlled by the new user option |
| 263 | 'mode-line-right-align-edge'. | 263 | 'mode-line-right-align-edge'. |
| 264 | 264 | ||
| 265 | ** Windows | ||
| 266 | |||
| 267 | *** New buffer display action alist entry 'post-command-select-window'. | ||
| 268 | It specifies whether the window of the displayed buffer should be | ||
| 269 | selected or deselected at the end of executing the current command. | ||
| 270 | |||
| 265 | ** Tab Bars and Tab Lines | 271 | ** Tab Bars and Tab Lines |
| 266 | 272 | ||
| 267 | *** New user option 'tab-bar-tab-name-format-functions'. | 273 | *** New user option 'tab-bar-tab-name-format-functions'. |
diff --git a/lisp/window.el b/lisp/window.el index 23977691f50..65651b2931b 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -7798,6 +7798,14 @@ Action alist entries are: | |||
| 7798 | and `preserve-size' are applied. The function is supposed | 7798 | and `preserve-size' are applied. The function is supposed |
| 7799 | to fill the window body with some contents that might depend | 7799 | to fill the window body with some contents that might depend |
| 7800 | on dimensions of the displayed window. | 7800 | on dimensions of the displayed window. |
| 7801 | `post-command-select-window' -- A non-nil value means that after the | ||
| 7802 | current command is executed and the hook `post-command-hook' is called, | ||
| 7803 | the window displayed by this function will be selected. A nil value | ||
| 7804 | means that if functions like `pop-to-buffer' selected another window, | ||
| 7805 | at the end of this command that window will be deselected, and the | ||
| 7806 | window that was selected before calling this function will remain | ||
| 7807 | selected regardless of which windows were selected afterwards within | ||
| 7808 | this command. | ||
| 7801 | 7809 | ||
| 7802 | The entries `window-height', `window-width', `window-size' and | 7810 | The entries `window-height', `window-width', `window-size' and |
| 7803 | `preserve-size' are applied only when the window used for | 7811 | `preserve-size' are applied only when the window used for |
| @@ -7853,6 +7861,17 @@ specified by the ACTION argument." | |||
| 7853 | (while (and functions (not window)) | 7861 | (while (and functions (not window)) |
| 7854 | (setq window (funcall (car functions) buffer alist) | 7862 | (setq window (funcall (car functions) buffer alist) |
| 7855 | functions (cdr functions))) | 7863 | functions (cdr functions))) |
| 7864 | (when-let ((select (assq 'post-command-select-window alist))) | ||
| 7865 | (letrec ((old-selected-window (selected-window)) | ||
| 7866 | (postfun | ||
| 7867 | (lambda () | ||
| 7868 | (if (cdr select) | ||
| 7869 | (when (window-live-p window) | ||
| 7870 | (select-window window)) | ||
| 7871 | (when (window-live-p old-selected-window) | ||
| 7872 | (select-window old-selected-window))) | ||
| 7873 | (remove-hook 'post-command-hook postfun)))) | ||
| 7874 | (add-hook 'post-command-hook postfun))) | ||
| 7856 | (and (windowp window) window)))) | 7875 | (and (windowp window) window)))) |
| 7857 | 7876 | ||
| 7858 | (defun display-buffer-other-frame (buffer) | 7877 | (defun display-buffer-other-frame (buffer) |