diff options
| author | Juri Linkov | 2024-04-02 19:51:51 +0300 |
|---|---|---|
| committer | Juri Linkov | 2024-04-02 19:51:51 +0300 |
| commit | 9af533dc751e5220a545ca7e15456992cbbfab98 (patch) | |
| tree | f07afabc6f3c7226b700ffca065177cdf4f8f1fe | |
| parent | a5fbb652ed3614d6735015551564f32b80e42c53 (diff) | |
| download | emacs-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.texi | 30 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/subr.el | 5 | ||||
| -rw-r--r-- | lisp/window.el | 4 |
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 |
| 2640 | set. | 2640 | set. |
| 2641 | |||
| 2642 | If the caller of @code{display-buffer} passes a category as a symbol | ||
| 2643 | in its @var{action} argument, then you can use the same category in | ||
| 2644 | @code{display-buffer-alist} to match buffers with different names, | ||
| 2645 | for 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 | |||
| 2659 | Regardless of the displayed buffer's name the caller defines a category | ||
| 2660 | as a symbol @code{comint}. Then @code{display-buffer-alist} matches | ||
| 2661 | this category for all buffers displayed with the same category. | ||
| 2662 | This avoids the need to construct a complex regular expression | ||
| 2663 | that 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 |
| 3355 | before calling this function will remain selected regardless of which | 3378 | before calling this function will remain selected regardless of which |
| 3356 | windows were selected afterwards within this command. | 3379 | windows were selected afterwards within this command. |
| 3380 | |||
| 3381 | @vindex category@r{, a buffer display action alist entry} | ||
| 3382 | @item category | ||
| 3383 | If the caller of @code{display-buffer} passes an alist entry | ||
| 3384 | @code{(category . symbol)} in its @var{action} argument, then you can | ||
| 3385 | match the displayed buffer by using the same category in the condition | ||
| 3386 | part of @code{display-buffer-alist} entries. | ||
| 3357 | @end table | 3387 | @end table |
| 3358 | 3388 | ||
| 3359 | By convention, the entries @code{window-height}, @code{window-width} | 3389 | By convention, the entries @code{window-height}, @code{window-width} |
| @@ -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'. | ||
| 296 | If the caller of 'display-buffer' passes '(category . symbol)' | ||
| 297 | in its 'action' argument, you can match the displayed buffer | ||
| 298 | by 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'. |
| 295 | It specifies whether the window of the displayed buffer should be | 303 | It specifies whether the window of the displayed buffer should be |
| 296 | selected or deselected at the end of executing the current command. | 304 | selected 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 | ||
| 7860 | The entries `window-height', `window-width', `window-size' and | 7864 | The 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 |