1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-25 07:28:20 +00:00

New condition/action entry 'category' for 'display-buffer' (bug#69983)

* doc/lispref/windows.texi (Choosing Window): Provide an example
of using '(category . comint)' in the condition of 'display-buffer-alist'
and in the action of 'display-buffer'.
(Buffer Display Action Alists): Add a new action alist entry 'category'.

* lisp/subr.el (buffer-match-p): Add a new condition 'category'.

* lisp/window.el (display-buffer): Document a new action alist entry
'category'.
This commit is contained in:
Juri Linkov 2024-04-02 19:51:51 +03:00
parent a5fbb652ed
commit 9af533dc75
4 changed files with 47 additions and 0 deletions

View File

@ -2638,6 +2638,29 @@ use @code{derived-mode} or @code{major-mode} as condition,
@code{buffer-match-p} could fail to report a match if
@code{display-buffer} is called before the major mode of the buffer is
set.
If the caller of @code{display-buffer} passes a category as a symbol
in its @var{action} argument, then you can use the same category in
@code{display-buffer-alist} to match buffers with different names,
for example:
@example
@group
(setopt
display-buffer-alist
(cons '((category . comint) (display-buffer-same-window))
display-buffer-alist))
(display-buffer (get-buffer-create "*my-shell*")
'(nil (category . comint)))
@end group
@end example
Regardless of the displayed buffer's name the caller defines a category
as a symbol @code{comint}. Then @code{display-buffer-alist} matches
this category for all buffers displayed with the same category.
This avoids the need to construct a complex regular expression
that matches a buffer name.
@end defopt
@defopt display-buffer-base-action
@ -3354,6 +3377,13 @@ If the value is @code{nil}, the buffer selected by such functions as
@code{pop-to-buffer} is deselected, and the window that was selected
before calling this function will remain selected regardless of which
windows were selected afterwards within this command.
@vindex category@r{, a buffer display action alist entry}
@item category
If the caller of @code{display-buffer} passes an alist entry
@code{(category . symbol)} in its @var{action} argument, then you can
match the displayed buffer by using the same category in the condition
part of @code{display-buffer-alist} entries.
@end table
By convention, the entries @code{window-height}, @code{window-width}

View File

@ -291,6 +291,14 @@ right-aligned to is controlled by the new user option
** Windows
+++
*** New action alist entry 'category' for 'display-buffer'.
If the caller of 'display-buffer' passes '(category . symbol)'
in its 'action' argument, you can match the displayed buffer
by adding '(category . symbol)' to the condition part of
'display-buffer-alist' entries.
+++
*** New action alist entry 'post-command-select-window' for 'display-buffer'.
It specifies whether the window of the displayed buffer should be
selected or deselected at the end of executing the current command.

View File

@ -7475,6 +7475,9 @@ CONDITION is either:
* `major-mode': the buffer matches if the buffer's major mode
is eq to the cons-cell's cdr. Prefer using `derived-mode'
instead when both can work.
* `category': the buffer matches a category as a symbol if
the caller of `display-buffer' provides `(category . symbol)'
in its action argument.
* `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.
@ -7503,6 +7506,8 @@ CONDITION is either:
(push condition buffer-match-p--past-warnings))
(apply condition buffer-or-name
(if args nil '(nil)))))))
(`(category . ,category)
(eq (alist-get 'category (cdar args)) category))
(`(major-mode . ,mode)
(eq
(buffer-local-value 'major-mode buffer)

View File

@ -7856,6 +7856,10 @@ Action alist entries are:
window that was selected before calling this function will remain
selected regardless of which windows were selected afterwards within
this command.
`category' -- If the caller of `display-buffer' passes an alist entry
`(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.
The entries `window-height', `window-width', `window-size' and
`preserve-size' are applied only when the window used for