diff options
| author | Dmitry Gutov | 2022-06-17 15:22:29 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2022-06-17 15:23:01 +0300 |
| commit | 4aca0d818f2d0b7dd7dc511907cc19f63758e482 (patch) | |
| tree | ef98174ad098d3a537568f72331da8f1a7dcc2d7 | |
| parent | 5e567af8e0608ccd6db37d548ccb36098eda95c4 (diff) | |
| download | emacs-4aca0d818f2d0b7dd7dc511907cc19f63758e482.tar.gz emacs-4aca0d818f2d0b7dd7dc511907cc19f63758e482.zip | |
buffer-match-p: Resolve backward compat concerns
* doc/lispref/buffers.texi (Buffer List): Document 'major-mode'
and 'derived-mode' predicates. Fix some typos.
* lisp/subr.el (buffer-match-p): Use the structure initially
pioneered by project-kill-buffer-conditions as-is (bug#54296).
* lisp/progmodes/project.el (project-kill-buffer-conditions)
(project--buffer-check): Revert the latest change.
(project--buffer-check): Add support for lambda predicates.
| -rw-r--r-- | doc/lispref/buffers.texi | 11 | ||||
| -rw-r--r-- | lisp/progmodes/project.el | 41 | ||||
| -rw-r--r-- | lisp/subr.el | 12 |
3 files changed, 33 insertions, 31 deletions
diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 1cbe8bc0933..aee440fe782 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi | |||
| @@ -981,13 +981,18 @@ of | |||
| 981 | Satisfied if @var{expr} doesn't satisfy @code{buffer-match-p} with | 981 | Satisfied if @var{expr} doesn't satisfy @code{buffer-match-p} with |
| 982 | the same buffer and @code{arg}. | 982 | the same buffer and @code{arg}. |
| 983 | @item or | 983 | @item or |
| 984 | Satisfied if @var{oper} is a list and @emph{any} condition if | 984 | Satisfied if @var{expr} is a list and @emph{any} condition in |
| 985 | @var{expr} satisfies @code{buffer-match-p}, with the same buffer and | 985 | @var{expr} satisfies @code{buffer-match-p}, with the same buffer and |
| 986 | @code{arg}. | 986 | @code{arg}. |
| 987 | @item and | 987 | @item and |
| 988 | Satisfied if @var{oper} is a list and @emph{all} condition if | 988 | Satisfied if @var{expr} is a list and @emph{all} conditions in |
| 989 | @var{expr} satisfies @code{buffer-match-p}, with the same buffer and | 989 | @var{expr} satisfy @code{buffer-match-p}, with the same buffer and |
| 990 | @code{arg}. | 990 | @code{arg}. |
| 991 | @item derived-mode | ||
| 992 | Satisfied if the buffer's major mode derives from @var{expr}. | ||
| 993 | @item major-mode | ||
| 994 | Satisfied if the buffer's major mode is equal to @var{expr}. Prefer | ||
| 995 | using @code{derived-mode} instead when both can work. | ||
| 991 | @end table | 996 | @end table |
| 992 | @end itemize | 997 | @end itemize |
| 993 | @end defun | 998 | @end defun |
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index f4d6742ed80..30f51704dca 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el | |||
| @@ -1221,22 +1221,18 @@ displayed." | |||
| 1221 | (display-buffer-other-frame buffer-or-name)) | 1221 | (display-buffer-other-frame buffer-or-name)) |
| 1222 | 1222 | ||
| 1223 | (defcustom project-kill-buffer-conditions | 1223 | (defcustom project-kill-buffer-conditions |
| 1224 | `(buffer-file-name ; All file-visiting buffers are included. | 1224 | '(buffer-file-name ; All file-visiting buffers are included. |
| 1225 | ;; Most of the temp buffers in the background: | 1225 | ;; Most of the temp buffers in the background: |
| 1226 | ,(lambda (buf) | 1226 | (major-mode . fundamental-mode) |
| 1227 | (not (eq (buffer-local-value 'major-mode buf) | ||
| 1228 | 'fundamental-mode))) | ||
| 1229 | ;; non-text buffer such as xref, occur, vc, log, ... | 1227 | ;; non-text buffer such as xref, occur, vc, log, ... |
| 1230 | (and (major-mode . special-mode) | 1228 | (and (derived-mode . special-mode) |
| 1231 | ,(lambda (buf) | 1229 | (not (major-mode . help-mode))) |
| 1232 | (not (eq (buffer-local-value 'major-mode buf) | 1230 | (derived-mode . compilation-mode) |
| 1233 | 'help-mode)))) | 1231 | (derived-mode . dired-mode) |
| 1234 | (major-mode . compilation-mode) | 1232 | (derived-mode . diff-mode) |
| 1235 | (major-mode . dired-mode) | 1233 | (derived-mode . comint-mode) |
| 1236 | (major-mode . diff-mode) | 1234 | (derived-mode . eshell-mode) |
| 1237 | (major-mode . comint-mode) | 1235 | (derived-mode . change-log-mode)) |
| 1238 | (major-mode . eshell-mode) | ||
| 1239 | (major-mode . change-log-mode)) | ||
| 1240 | "List of conditions to kill buffers related to a project. | 1236 | "List of conditions to kill buffers related to a project. |
| 1241 | This list is used by `project-kill-buffers'. | 1237 | This list is used by `project-kill-buffers'. |
| 1242 | Each condition is either: | 1238 | Each condition is either: |
| @@ -1246,11 +1242,9 @@ Each condition is either: | |||
| 1246 | - a cons-cell, where the car describes how to interpret the cdr. | 1242 | - a cons-cell, where the car describes how to interpret the cdr. |
| 1247 | The car can be one of the following: | 1243 | The car can be one of the following: |
| 1248 | * `major-mode': the buffer is killed if the buffer's major | 1244 | * `major-mode': the buffer is killed if the buffer's major |
| 1249 | mode is derived from the major mode denoted by the cons-cell's | 1245 | mode is eq to the cons-cell's cdr. |
| 1250 | cdr. | ||
| 1251 | * `derived-mode': the buffer is killed if the buffer's major | 1246 | * `derived-mode': the buffer is killed if the buffer's major |
| 1252 | mode is eq to the cons-cell's cdr (this is deprecated and will | 1247 | mode is derived from the major mode in the cons-cell's cdr. |
| 1253 | result in a warning if used). | ||
| 1254 | * `not': the cdr is interpreted as a negation of a condition. | 1248 | * `not': the cdr is interpreted as a negation of a condition. |
| 1255 | * `and': the cdr is a list of recursive conditions, that all have | 1249 | * `and': the cdr is a list of recursive conditions, that all have |
| 1256 | to be met. | 1250 | to be met. |
| @@ -1308,15 +1302,12 @@ form of CONDITIONS." | |||
| 1308 | (when (cond | 1302 | (when (cond |
| 1309 | ((stringp c) | 1303 | ((stringp c) |
| 1310 | (string-match-p c (buffer-name buf))) | 1304 | (string-match-p c (buffer-name buf))) |
| 1311 | ((symbolp c) | 1305 | ((functionp c) |
| 1312 | (funcall c buf)) | 1306 | (funcall c buf)) |
| 1313 | ((eq (car-safe c) 'derived-mode) | ||
| 1314 | (warn "The use of `derived-mode' in \ | ||
| 1315 | `project--buffer-check' is deprecated.") | ||
| 1316 | (provided-mode-derived-p | ||
| 1317 | (buffer-local-value 'major-mode buf) | ||
| 1318 | (cdr c))) | ||
| 1319 | ((eq (car-safe c) 'major-mode) | 1307 | ((eq (car-safe c) 'major-mode) |
| 1308 | (eq (buffer-local-value 'major-mode buf) | ||
| 1309 | (cdr c))) | ||
| 1310 | ((eq (car-safe c) 'derived-mode) | ||
| 1320 | (provided-mode-derived-p | 1311 | (provided-mode-derived-p |
| 1321 | (buffer-local-value 'major-mode buf) | 1312 | (buffer-local-value 'major-mode buf) |
| 1322 | (cdr c))) | 1313 | (cdr c))) |
diff --git a/lisp/subr.el b/lisp/subr.el index 50ae357a136..c1c9759b03d 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -6855,9 +6855,11 @@ CONDITION is either: | |||
| 6855 | arguments, and returns non-nil if the buffer matches, | 6855 | arguments, and returns non-nil if the buffer matches, |
| 6856 | - a cons-cell, where the car describes how to interpret the cdr. | 6856 | - a cons-cell, where the car describes how to interpret the cdr. |
| 6857 | The car can be one of the following: | 6857 | The car can be one of the following: |
| 6858 | * `major-mode': the buffer matches if the buffer's major | 6858 | * `derived-mode': the buffer matches if the buffer's major mode |
| 6859 | mode is derived from the major mode denoted by the cons-cell's | 6859 | is derived from the major mode in the cons-cell's cdr. |
| 6860 | cdr | 6860 | * `major-mode': the buffer matches if the buffer's major mode |
| 6861 | is eq to the cons-cell's cdr. Prefer using `derived-mode' | ||
| 6862 | instead when both can work. | ||
| 6861 | * `not': the cdr is interpreted as a negation of a condition. | 6863 | * `not': the cdr is interpreted as a negation of a condition. |
| 6862 | * `and': the cdr is a list of recursive conditions, that all have | 6864 | * `and': the cdr is a list of recursive conditions, that all have |
| 6863 | to be met. | 6865 | to be met. |
| @@ -6877,6 +6879,10 @@ CONDITION is either: | |||
| 6877 | (funcall condition buffer) | 6879 | (funcall condition buffer) |
| 6878 | (funcall condition buffer arg))) | 6880 | (funcall condition buffer arg))) |
| 6879 | ((eq (car-safe condition) 'major-mode) | 6881 | ((eq (car-safe condition) 'major-mode) |
| 6882 | (eq | ||
| 6883 | (buffer-local-value 'major-mode buffer) | ||
| 6884 | (cdr condition))) | ||
| 6885 | ((eq (car-safe condition) 'derived-mode) | ||
| 6880 | (provided-mode-derived-p | 6886 | (provided-mode-derived-p |
| 6881 | (buffer-local-value 'major-mode buffer) | 6887 | (buffer-local-value 'major-mode buffer) |
| 6882 | (cdr condition))) | 6888 | (cdr condition))) |