aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2024-04-02 19:51:51 +0300
committerJuri Linkov2024-04-02 19:51:51 +0300
commit9af533dc751e5220a545ca7e15456992cbbfab98 (patch)
treef07afabc6f3c7226b700ffca065177cdf4f8f1fe
parenta5fbb652ed3614d6735015551564f32b80e42c53 (diff)
downloademacs-9af533dc751e5220a545ca7e15456992cbbfab98.tar.gz
emacs-9af533dc751e5220a545ca7e15456992cbbfab98.zip
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'.
-rw-r--r--doc/lispref/windows.texi30
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/subr.el5
-rw-r--r--lisp/window.el4
4 files changed, 47 insertions, 0 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index eef05d94fdb..d3d6b854461 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -2638,6 +2638,29 @@ use @code{derived-mode} or @code{major-mode} as condition,
2638@code{buffer-match-p} could fail to report a match if 2638@code{buffer-match-p} could fail to report a match if
2639@code{display-buffer} is called before the major mode of the buffer is 2639@code{display-buffer} is called before the major mode of the buffer is
2640set. 2640set.
2641
2642If the caller of @code{display-buffer} passes a category as a symbol
2643in its @var{action} argument, then you can use the same category in
2644@code{display-buffer-alist} to match buffers with different names,
2645for example:
2646
2647@example
2648@group
2649(setopt
2650 display-buffer-alist
2651 (cons '((category . comint) (display-buffer-same-window))
2652 display-buffer-alist))
2653
2654(display-buffer (get-buffer-create "*my-shell*")
2655 '(nil (category . comint)))
2656@end group
2657@end example
2658
2659Regardless of the displayed buffer's name the caller defines a category
2660as a symbol @code{comint}. Then @code{display-buffer-alist} matches
2661this category for all buffers displayed with the same category.
2662This avoids the need to construct a complex regular expression
2663that matches a buffer name.
2641@end defopt 2664@end defopt
2642 2665
2643@defopt display-buffer-base-action 2666@defopt display-buffer-base-action
@@ -3354,6 +3377,13 @@ 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 3377@code{pop-to-buffer} is deselected, and the window that was selected
3355before calling this function will remain selected regardless of which 3378before calling this function will remain selected regardless of which
3356windows were selected afterwards within this command. 3379windows were selected afterwards within this command.
3380
3381@vindex category@r{, a buffer display action alist entry}
3382@item category
3383If the caller of @code{display-buffer} passes an alist entry
3384@code{(category . symbol)} in its @var{action} argument, then you can
3385match the displayed buffer by using the same category in the condition
3386part of @code{display-buffer-alist} entries.
3357@end table 3387@end table
3358 3388
3359By convention, the entries @code{window-height}, @code{window-width} 3389By convention, the entries @code{window-height}, @code{window-width}
diff --git a/etc/NEWS b/etc/NEWS
index 4b0f148dc5d..47275db47e3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -291,6 +291,14 @@ right-aligned to is controlled by the new user option
291 291
292** Windows 292** Windows
293 293
294+++
295*** New action alist entry 'category' for 'display-buffer'.
296If the caller of 'display-buffer' passes '(category . symbol)'
297in its 'action' argument, you can match the displayed buffer
298by adding '(category . symbol)' to the condition part of
299'display-buffer-alist' entries.
300
301+++
294*** New action alist entry 'post-command-select-window' for 'display-buffer'. 302*** New action alist entry 'post-command-select-window' for 'display-buffer'.
295It specifies whether the window of the displayed buffer should be 303It specifies whether the window of the displayed buffer should be
296selected or deselected at the end of executing the current command. 304selected or deselected at the end of executing the current command.
diff --git a/lisp/subr.el b/lisp/subr.el
index 50487e2c734..753c0144ca5 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -7475,6 +7475,9 @@ CONDITION is either:
7475 * `major-mode': the buffer matches if the buffer's major mode 7475 * `major-mode': the buffer matches if the buffer's major mode
7476 is eq to the cons-cell's cdr. Prefer using `derived-mode' 7476 is eq to the cons-cell's cdr. Prefer using `derived-mode'
7477 instead when both can work. 7477 instead when both can work.
7478 * `category': the buffer matches a category as a symbol if
7479 the caller of `display-buffer' provides `(category . symbol)'
7480 in its action argument.
7478 * `not': the cadr is interpreted as a negation of a condition. 7481 * `not': the cadr is interpreted as a negation of a condition.
7479 * `and': the cdr is a list of recursive conditions, that all have 7482 * `and': the cdr is a list of recursive conditions, that all have
7480 to be met. 7483 to be met.
@@ -7503,6 +7506,8 @@ CONDITION is either:
7503 (push condition buffer-match-p--past-warnings)) 7506 (push condition buffer-match-p--past-warnings))
7504 (apply condition buffer-or-name 7507 (apply condition buffer-or-name
7505 (if args nil '(nil))))))) 7508 (if args nil '(nil)))))))
7509 (`(category . ,category)
7510 (eq (alist-get 'category (cdar args)) category))
7506 (`(major-mode . ,mode) 7511 (`(major-mode . ,mode)
7507 (eq 7512 (eq
7508 (buffer-local-value 'major-mode buffer) 7513 (buffer-local-value 'major-mode buffer)
diff --git a/lisp/window.el b/lisp/window.el
index df55a7ca673..46de1819c69 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7856,6 +7856,10 @@ Action alist entries are:
7856 window that was selected before calling this function will remain 7856 window that was selected before calling this function will remain
7857 selected regardless of which windows were selected afterwards within 7857 selected regardless of which windows were selected afterwards within
7858 this command. 7858 this command.
7859 `category' -- If the caller of `display-buffer' passes an alist entry
7860 `(category . symbol)' in its action argument, then you can match
7861 the displayed buffer by using the same category in the condition
7862 part of `display-buffer-alist' entries.
7859 7863
7860The entries `window-height', `window-width', `window-size' and 7864The entries `window-height', `window-width', `window-size' and
7861`preserve-size' are applied only when the window used for 7865`preserve-size' are applied only when the window used for