diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 3a8dffd1af1..82b670fd634 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/etc/NEWS b/etc/NEWS index e080d8ed3a2..6fa979a2785 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -312,6 +312,11 @@ When bound to non-nil, 'window-state-get' will normalize 'uniquify' managed buffer names by removing 'uniquify' prefixes and suffixes. This helps to restore window buffers across Emacs sessions. ++++ +*** New action alist entry 'this-command' for 'display-buffer'. +You can use this in 'display-buffer-alist' to match buffers displayed +during the execution of particular commands. + ** Frames +++ diff --git a/lisp/subr.el b/lisp/subr.el index a5c850ebe5e..975f28e0a17 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7629,6 +7629,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. @@ -7659,6 +7664,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 e0e626e9500..afa9a156e46 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -8236,6 +8236,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