diff options
| author | Eli Zaretskii | 2025-08-08 14:39:34 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2025-08-08 14:39:34 +0300 |
| commit | 5d5a00e4ade7ef2e243947813aa26c0da8eb579a (patch) | |
| tree | 3cb840d25f8947e91c3897f34460aba97e79c405 /lisp/autoinsert.el | |
| parent | 4456f7bd313ab829ba3ec6375349a693dbbc1930 (diff) | |
| download | emacs-5d5a00e4ade7ef2e243947813aa26c0da8eb579a.tar.gz emacs-5d5a00e4ade7ef2e243947813aa26c0da8eb579a.zip | |
Revert "Autoinsert: Allow condition to be a function"
This reverts commit 738a7bb4949fdc93b0b637ac4c65423c928f0924.
It caused regressions in autoinsert-tests, and causes
conceptual problems due to its design. (Bug#79178)
Diffstat (limited to 'lisp/autoinsert.el')
| -rw-r--r-- | lisp/autoinsert.el | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/lisp/autoinsert.el b/lisp/autoinsert.el index 3c4057f1623..e7492d1b9ed 100644 --- a/lisp/autoinsert.el +++ b/lisp/autoinsert.el | |||
| @@ -323,10 +323,8 @@ The document was typeset with | |||
| 323 | ")) | 323 | ")) |
| 324 | "A list specifying text to insert by default into a new file. | 324 | "A list specifying text to insert by default into a new file. |
| 325 | Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION). | 325 | Elements look like (CONDITION . ACTION) or ((CONDITION . DESCRIPTION) . ACTION). |
| 326 | CONDITION may be a regexp that must match the new file's name or a symbol that | 326 | CONDITION may be a regexp that must match the new file's name, or it may be |
| 327 | must match the major mode for this element to apply. | 327 | a symbol that must match the major mode for this element to apply. |
| 328 | CONDITION can also be custom predicate function of no arguments; Emacs will | ||
| 329 | insert the text if the predicate function returns non-nil. | ||
| 330 | Only the first matching element is effective. | 328 | Only the first matching element is effective. |
| 331 | Optional DESCRIPTION is a string for filling `auto-insert-prompt'. | 329 | Optional DESCRIPTION is a string for filling `auto-insert-prompt'. |
| 332 | ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute | 330 | ACTION may be a skeleton to insert (see `skeleton-insert'), an absolute |
| @@ -370,25 +368,12 @@ Matches the visited file name against the elements of `auto-insert-alist'." | |||
| 370 | (pcase-lambda (`(,cond . ,action)) | 368 | (pcase-lambda (`(,cond . ,action)) |
| 371 | (if (atom cond) | 369 | (if (atom cond) |
| 372 | (setq desc cond) | 370 | (setq desc cond) |
| 373 | ;; if `cond' is a lambda, don't split it but set `desc' to a custom string | 371 | (setq desc (cdr cond) |
| 374 | (if (and (not (symbolp cond)) (functionp cond)) | 372 | cond (car cond))) |
| 375 | (setq desc "`lambda condition'") | 373 | (when (if (symbolp cond) |
| 376 | (setq desc (cdr cond) | 374 | (derived-mode-p cond) |
| 377 | cond (car cond)))) | ||
| 378 | (when (cond | ||
| 379 | ;; `cond' should be a major-mode variable | ||
| 380 | ((and (symbolp cond) (not (functionp cond))) | ||
| 381 | (derived-mode-p cond)) | ||
| 382 | |||
| 383 | ;; `cond' should be a predicate that takes no argument | ||
| 384 | ;; It can either be a named function or a lambda | ||
| 385 | ((functionp cond) | ||
| 386 | (funcall cond)) | ||
| 387 | |||
| 388 | ;; cond should be a regexp | ||
| 389 | (t | ||
| 390 | (and buffer-file-name | 375 | (and buffer-file-name |
| 391 | (string-match cond buffer-file-name)))) | 376 | (string-match cond buffer-file-name))) |
| 392 | action)) | 377 | action)) |
| 393 | auto-insert-alist))) | 378 | auto-insert-alist))) |
| 394 | (goto-char 1) | 379 | (goto-char 1) |