diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index eef05d94fdb..54e563eeb58 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -2638,6 +2638,23 @@ Choosing Window @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. + +When the caller of @code{display-buffer} passes a category as a symbol +in its @var{action} argument, then @code{display-buffer-alist} can use it +to match a whole category of buffers with different buffer 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 @end defopt @defopt display-buffer-base-action diff --git a/lisp/subr.el b/lisp/subr.el index 90dbfc75d52..9319acefbf1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7476,6 +7474,8 @@ buffer-match-p * `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 if the caller of `display-buffer' + provided `(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. @@ -7504,6 +7504,8 @@ buffer-match-p (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)