diff options
| author | Federico Tedin | 2020-02-17 22:24:40 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2020-02-21 11:15:00 +0200 |
| commit | 97b8a78334d22a6b12cc0f922771baf67a4030bc (patch) | |
| tree | ef00d7258184f9185b65acd54b0df05f0beec83c /lisp | |
| parent | 41450a8ea5a156a34f6641a0768cadb174fa261c (diff) | |
| download | emacs-97b8a78334d22a6b12cc0f922771baf67a4030bc.tar.gz emacs-97b8a78334d22a6b12cc0f922771baf67a4030bc.zip | |
Allow tempo-define-template to reassign tags to new templates
* lisp/tempo.el (tempo-define-template): Update documentation string
to mention that existing tags can be reassigned new templates.
(tempo-add-tag): Allow reassigning tags to new templates.
Additionally, invalidate tag collections in all buffers if the global
tags list is being modified.
(tempo-invalidate-collection): Allow invalidating tag collections in
all buffers at the same time.
* test/lisp/tempo-tests.el (tempo-define-tag-globally-test): Add a
test to check that new templates plus tags can be defined from any
buffer and then immediately used in other buffers.
(tempo-overwrite-tag-test): Add a test to check that tags can be
reassigned templates.
* etc/NEWS: Announce changes in tempo.el.
(Bug#39555)
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/tempo.el | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/lisp/tempo.el b/lisp/tempo.el index 9de5ac66c7d..2da90f08c87 100644 --- a/lisp/tempo.el +++ b/lisp/tempo.el | |||
| @@ -220,7 +220,9 @@ list of elements in the template, TAG is the tag used for completion, | |||
| 220 | DOCUMENTATION is the documentation string for the insertion command | 220 | DOCUMENTATION is the documentation string for the insertion command |
| 221 | created, and TAGLIST (a symbol) is the tag list that TAG (if provided) | 221 | created, and TAGLIST (a symbol) is the tag list that TAG (if provided) |
| 222 | should be added to. If TAGLIST is nil and TAG is non-nil, TAG is | 222 | should be added to. If TAGLIST is nil and TAG is non-nil, TAG is |
| 223 | added to `tempo-tags'. | 223 | added to `tempo-tags'. If TAG already corresponds to a template in |
| 224 | the tag list, modify the list so that TAG now corresponds to the newly | ||
| 225 | defined template. | ||
| 224 | 226 | ||
| 225 | The elements in ELEMENTS can be of several types: | 227 | The elements in ELEMENTS can be of several types: |
| 226 | 228 | ||
| @@ -579,14 +581,20 @@ and insert the results." | |||
| 579 | (defun tempo-add-tag (tag template &optional tag-list) | 581 | (defun tempo-add-tag (tag template &optional tag-list) |
| 580 | "Add a template tag. | 582 | "Add a template tag. |
| 581 | Add the TAG, that should complete to TEMPLATE to the list in TAG-LIST, | 583 | Add the TAG, that should complete to TEMPLATE to the list in TAG-LIST, |
| 582 | or to `tempo-tags' if TAG-LIST is nil." | 584 | or to `tempo-tags' if TAG-LIST is nil. If TAG was already in the list, |
| 585 | replace its template with TEMPLATE." | ||
| 583 | 586 | ||
| 584 | (interactive "sTag: \nCTemplate: ") | 587 | (interactive "sTag: \nCTemplate: ") |
| 585 | (if (null tag-list) | 588 | (if (null tag-list) |
| 586 | (setq tag-list 'tempo-tags)) | 589 | (setq tag-list 'tempo-tags)) |
| 587 | (if (not (assoc tag (symbol-value tag-list))) | 590 | (let ((entry (assoc tag (symbol-value tag-list)))) |
| 588 | (set tag-list (cons (cons tag template) (symbol-value tag-list)))) | 591 | (if entry |
| 589 | (tempo-invalidate-collection)) | 592 | ;; Tag is already in the list, assign a new template to it |
| 593 | (setcdr entry template) | ||
| 594 | ;; Tag is not present in the list, add it with its template | ||
| 595 | (set tag-list (cons (cons tag template) (symbol-value tag-list))))) | ||
| 596 | ;; Invalidate globally if we're modifying `tempo-tags' | ||
| 597 | (tempo-invalidate-collection (eq tag-list 'tempo-tags))) | ||
| 590 | 598 | ||
| 591 | ;;; | 599 | ;;; |
| 592 | ;;; tempo-use-tag-list | 600 | ;;; tempo-use-tag-list |
| @@ -609,10 +617,17 @@ COMPLETION-FUNCTION just sets `tempo-match-finder' locally." | |||
| 609 | ;;; | 617 | ;;; |
| 610 | ;;; tempo-invalidate-collection | 618 | ;;; tempo-invalidate-collection |
| 611 | 619 | ||
| 612 | (defun tempo-invalidate-collection () | 620 | (defun tempo-invalidate-collection (&optional global) |
| 613 | "Marks the tag collection as obsolete. | 621 | "Marks the tag collection as obsolete. |
| 614 | Whenever it is needed again it will be rebuilt." | 622 | Whenever it is needed again it will be rebuilt. If GLOBAL is non-nil, |
| 615 | (setq tempo-dirty-collection t)) | 623 | mark the tag collection of all buffers as obsolete, not just the |
| 624 | current one." | ||
| 625 | (if global | ||
| 626 | (dolist (buffer (buffer-list)) | ||
| 627 | (with-current-buffer buffer | ||
| 628 | (when (assq 'tempo-dirty-collection (buffer-local-variables)) | ||
| 629 | (setq tempo-dirty-collection t)))) | ||
| 630 | (setq tempo-dirty-collection t))) | ||
| 616 | 631 | ||
| 617 | ;;; | 632 | ;;; |
| 618 | ;;; tempo-build-collection | 633 | ;;; tempo-build-collection |