From f45ff8e4f6d58d577ce30e123e99772b0f4b062d Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 1 May 2025 20:55:56 +0800 Subject: [PATCH] New this-command buffer display action alist entry * lisp/subr.el (buffer-match-p): New this-command cons cell condition to implement new this-command buffer display action alist entry (bug#78082). * lisp/window.el (display-buffer): * doc/lispref/windows.texi (Buffer Display Action Alists): * etc/NEWS: Document the new buffer display action alist entry. (cherry picked from commit 343f0c44f35c41b93c66f67da0ddeceb98bbdb93) --- doc/lispref/windows.texi | 8 ++++++++ lisp/subr.el | 9 +++++++++ lisp/window.el | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 417c323be6b..96b97d0cffb 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -3914,6 +3914,14 @@ List, @code{buffer-match-p}}. Thus, if a Lisp program uses a particular @var{symbol} as the category when calling @code{display-buffer}, users can customize how these buffers will be displayed by including such an entry in @code{display-buffer-alist}. + +@vindex this-command@r{, a buffer display action alist entry} +@item this-command +The value is a symbol naming a command or a list of such symbols. It +means the condition when that command, or any of those commands, are now +being executed. You can use this in the condition part of +@code{display-buffer-alist} entries to match buffers displayed during +the execution of particular commands. @end table By convention, the entries @code{window-height}, @code{window-width} diff --git a/lisp/subr.el b/lisp/subr.el index 47e020d4337..94c337559e5 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7086,6 +7086,11 @@ CONDITION is either: the buffer matches if the caller of `display-buffer' provides `(category . SYMBOL)' in its ACTION argument, and SYMBOL is `eq' to the cons-cell's cdr. + * `this-command': the buffer matches if the command now being executed + is `eq' to or a `memq' of the cons-cell's cdr. + (This case is not useful when calling `buffer-match-p' directly, but + is needed to support the `this-command' buffer display action alist + entry. See `display-buffer'.) * `not': the cadr is interpreted as a negation of a condition. * `and': the cdr is a list of recursive conditions, that all have to be met. @@ -7116,6 +7121,10 @@ CONDITION is either: (if args nil '(nil))))))) (`(category . ,category) (eq (alist-get 'category (cdar args)) category)) + (`(this-command . ,command-or-commands) + (if (listp command-or-commands) + (memq this-command command-or-commands) + (eq this-command command-or-commands))) (`(major-mode . ,mode) (eq (buffer-local-value 'major-mode buffer) diff --git a/lisp/window.el b/lisp/window.el index 052547de7df..746133005be 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -8184,6 +8184,11 @@ Action alist entries are: `(category . symbol)' in its action argument, then you can match the displayed buffer by using the same category in the condition part of `display-buffer-alist' entries. + `this-command' -- A symbol naming the command now being executed, or a + list of such symbols to mean the condition when any of those commands + are now being executed. + You can use this in the condition part of `display-buffer-alist' + entries to match buffers displayed by particular commands. The entries `window-height', `window-width', `window-size' and `preserve-size' are applied only when the window used for -- 2.39.5