From unknown Sat Jun 14 18:52:40 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#39555 <39555@debbugs.gnu.org> To: bug#39555 <39555@debbugs.gnu.org> Subject: Status: [PATCH] Allow tempo-define-template to reassign tags to new templates Reply-To: bug#39555 <39555@debbugs.gnu.org> Date: Sun, 15 Jun 2025 01:52:40 +0000 retitle 39555 [PATCH] Allow tempo-define-template to reassign tags to new t= emplates reassign 39555 emacs submitter 39555 Federico Tedin severity 39555 normal tag 39555 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 10 17:34:20 2020 Received: (at submit) by debbugs.gnu.org; 10 Feb 2020 22:34:20 +0000 Received: from localhost ([127.0.0.1]:55677 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j1HdE-0008BN-CY for submit@debbugs.gnu.org; Mon, 10 Feb 2020 17:34:20 -0500 Received: from lists.gnu.org ([209.51.188.17]:56275) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j1HdC-0008BE-PH for submit@debbugs.gnu.org; Mon, 10 Feb 2020 17:34:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41652) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1Hd9-00049Q-65 for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 17:34:18 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1Hd7-00081y-L7 for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 17:34:15 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:56093) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j1Hd7-000802-9y for bug-gnu-emacs@gnu.org; Mon, 10 Feb 2020 17:34:13 -0500 Received: by mail-wm1-x341.google.com with SMTP id q9so1066034wmj.5 for ; Mon, 10 Feb 2020 14:34:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=zfqTBjceWMlcOfvRX6cyMOH0dxV3Z6q+I66bm1ObztM=; b=nVxwbwK1eu0oGyidjNe2Bw6repmRPquuNJpGnNGoWwhWOrC73DmDfcN3fXug1mehIi N4dmM3QVYDod4/DPdmtAbw5Zo2h1EQ15M2eorBkvZfagSmzu60/W5lC+2GwFZQV3ETNe 8x3AAxjTj2ou8GHXZDl8oAqkFIfuoX6b28cg9TrCoIzyjloo95V3iPa3SNPUzvJDPqmJ lUrkbZtNOhrAMn5aMvTOknXGULNxpJcAhjW/INO9evU7qfIGSL+SkR85h96rt1qeVVUS Qs9Ygh7zqeg2TnfEcszL1kXqxjLjaujqE++0mh8siadMu9mYmqvsIawFrkbN4UJAgLgq lj2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=zfqTBjceWMlcOfvRX6cyMOH0dxV3Z6q+I66bm1ObztM=; b=gwbeyU9l0dKn5GVPdpY5DRNweOUxfKp5YcTQimqMeQuJ/vEzw5976pQoGhy/05AGBm LzUybPipoJqQfZdo0TkBTNkGHwpq9Uxfr7aSE2YN7S07h6P6jCHRuyeS0jgwx3eRDhmw +J0oxVp0txvlc5lI80ztyeum8IXnpDkQVyLRLGjbbzKBUe7vAYL2QBBsIalfiMpZ+y/U j0jrPhBoRjiNpspoAalmJq8zhPe1WISZmEkXt8ZLkN9b2p0kst/nBiTTe4VzeKZVwvQt kDsl9GaBEb54OUE2/DCgHkvtpGSMRFkIR/lywCbtt5GRVb+JT3BA/XOU+YYUCr4nDh6C qcww== X-Gm-Message-State: APjAAAUAlRF5t7l2bjEcHiNGB0R8wP85fBqisV2X07y1kk2F3REomu4T j36yzzGV8y9fpa5HSQuv/vxXmPSL X-Google-Smtp-Source: APXvYqz1cP+/BX5tgqEeGMP1CNBdMLbuqQTs70c6A1v2LJgLszeVIuPr6ozUi/2/MZ3gdYq01BLJrA== X-Received: by 2002:a1c:f717:: with SMTP id v23mr1222906wmh.172.1581374051375; Mon, 10 Feb 2020 14:34:11 -0800 (PST) Received: from lead (ip-109-41-1-62.web.vodafone.de. [109.41.1.62]) by smtp.gmail.com with ESMTPSA id f62sm972691wmf.36.2020.02.10.14.34.05 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Feb 2020 14:34:06 -0800 (PST) From: Federico Tedin To: bug-gnu-emacs@gnu.org Subject: [PATCH] Allow tempo-define-template to reassign tags to new templates Date: Mon, 10 Feb 2020 23:34:04 +0100 Message-ID: <877e0u9in7.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 X-Spam-Score: 2.3 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: (This may apply as a bug and as a wishlist item at the same time - not sure) Two problems I've found using tempo.el are: 1) If I'm using templates + tags (with `tempo-complete-tag') in a buffer, and I define new templates + tags from another buffer, I can't immediately use them in the original buffer (I have to do M-: ( [...] Content analysis details: (2.3 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (federicotedin[at]gmail.com) 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [209.51.188.17 listed in list.dnswl.org] 2.0 SPOOFED_FREEMAIL No description available. X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --=-=-= Content-Type: text/plain (This may apply as a bug and as a wishlist item at the same time - not sure) Two problems I've found using tempo.el are: 1) If I'm using templates + tags (with `tempo-complete-tag') in a buffer, and I define new templates + tags from another buffer, I can't immediately use them in the original buffer (I have to do M-: (setq tempo-dirty-collection t) ). 2) If I want to assign a different template to an already existing tag, I have to remove the tag manually from the tags collection. These two problems can become a bit annoying specially when writing/trying out new templates with tags. For someone learning about tempo.el for the first time, I can imagine they could be a problem as well. To fix these, I'm attaching a patch with some changes. In `tempo-invalidate-collection', I decided to loop over every buffer to check if `tempo-dirty-collection' has a local value, and only set it to t if it does. I am not sure if this is the ideal way of setting a buffer-local variable to a certain value for all buffers that have bound a local value to it. Feedback is welcome. - Fede --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=tempo.patch Content-Description: patch >From d5495b81919b4dbe48a7d81f4eb89bb5d4d4a45b Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Mon, 10 Feb 2020 23:18:16 +0100 Subject: [PATCH 1/1] 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. --- lisp/tempo.el | 31 +++++++++++++++++++++++-------- test/lisp/tempo-tests.el | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/lisp/tempo.el b/lisp/tempo.el index 9de5ac66c7..3d19fc135b 100644 --- a/lisp/tempo.el +++ b/lisp/tempo.el @@ -220,7 +220,9 @@ tempo-define-template DOCUMENTATION is the documentation string for the insertion command created, and TAGLIST (a symbol) is the tag list that TAG (if provided) should be added to. If TAGLIST is nil and TAG is non-nil, TAG is -added to `tempo-tags'. +added to `tempo-tags'. If TAG already corresponds to a template in +the tag list, modify the list so that TAG now corresponds to the newly +defined template. The elements in ELEMENTS can be of several types: @@ -579,14 +581,20 @@ tempo-backward-mark (defun tempo-add-tag (tag template &optional tag-list) "Add a template tag. Add the TAG, that should complete to TEMPLATE to the list in TAG-LIST, -or to `tempo-tags' if TAG-LIST is nil." +or to `tempo-tags' if TAG-LIST is nil. If TAG was already in the list, +replace its template with TEMPLATE." (interactive "sTag: \nCTemplate: ") (if (null tag-list) (setq tag-list 'tempo-tags)) - (if (not (assoc tag (symbol-value tag-list))) - (set tag-list (cons (cons tag template) (symbol-value tag-list)))) - (tempo-invalidate-collection)) + (let ((entry (assoc tag (symbol-value tag-list)))) + (if entry + ;; Tag is already in the list, assign a new template to it + (setcdr entry template) + ;; Tag is not present in the list, add it with its template + (set tag-list (cons (cons tag template) (symbol-value tag-list))))) + ;; Invalidate globally if we're modifying `tempo-tags' + (tempo-invalidate-collection (eq tag-list 'tempo-tags))) ;;; ;;; tempo-use-tag-list @@ -609,10 +617,17 @@ tempo-use-tag-list ;;; ;;; tempo-invalidate-collection -(defun tempo-invalidate-collection () +(defun tempo-invalidate-collection (&optional global) "Marks the tag collection as obsolete. -Whenever it is needed again it will be rebuilt." - (setq tempo-dirty-collection t)) +Whenever it is needed again it will be rebuilt. When GLOBAL is +non-nil, mark the tag collection of all buffers as obsolete, not just +the current one." + (if global + (dolist (buffer (buffer-list)) + (with-current-buffer buffer + (when (assq 'tempo-dirty-collection (buffer-local-variables)) + (setq tempo-dirty-collection t)))) + (setq tempo-dirty-collection t))) ;;; ;;; tempo-build-collection diff --git a/test/lisp/tempo-tests.el b/test/lisp/tempo-tests.el index 0dd310b853..bfe475910d 100644 --- a/test/lisp/tempo-tests.el +++ b/test/lisp/tempo-tests.el @@ -216,6 +216,45 @@ tempo-expand-tag-test (tempo-complete-tag) (should (equal (buffer-string) "Hello, World!")))) +(ert-deftest tempo-define-tag-globally-test () + "Testing usage of a template tag defined from another buffer." + (tempo-define-template "test" '("Hello, World!") "hello") + + (with-temp-buffer + ;; Use a tag in buffer 1 + (insert "hello") + (tempo-complete-tag) + (should (equal (buffer-string) "Hello, World!")) + (erase-buffer) + + ;; Collection should not be dirty + (should-not tempo-dirty-collection) + + ;; Define a tag on buffer 2 + (with-temp-buffer + (tempo-define-template "test2" '("Now expanded.") "mytag")) + + ;; I should be able to use this template back in buffer 1 + (insert "mytag") + (tempo-complete-tag) + (should (equal (buffer-string) "Now expanded.")))) + +(ert-deftest tempo-overwrite-tag-test () + "Testing ability to reassign templates to tags." + (with-temp-buffer + ;; Define a tag and use it + (tempo-define-template "test-tag-1" '("abc") "footag") + (insert "footag") + (tempo-complete-tag) + (should (equal (buffer-string) "abc")) + (erase-buffer) + + ;; Define a new template with the same tag + (tempo-define-template "test-tag-2" '("xyz") "footag") + (insert "footag") + (tempo-complete-tag) + (should (equal (buffer-string) "xyz")))) + (ert-deftest tempo-expand-partial-tag-test () "Testing expansion of a template with a tag, with a partial match." (with-temp-buffer -- 2.17.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 14 05:12:09 2020 Received: (at 39555) by debbugs.gnu.org; 14 Feb 2020 10:12:09 +0000 Received: from localhost ([127.0.0.1]:60888 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j2XxB-00012a-Bb for submit@debbugs.gnu.org; Fri, 14 Feb 2020 05:12:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45443) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j2Xx9-00012H-7o for 39555@debbugs.gnu.org; Fri, 14 Feb 2020 05:12:07 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1j2Xx2-0001C4-4r; Fri, 14 Feb 2020 05:12:02 -0500 Received: from [176.228.60.248] (port=2912 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1j2Xx1-00006a-K9; Fri, 14 Feb 2020 05:11:59 -0500 Date: Fri, 14 Feb 2020 12:12:03 +0200 Message-Id: <835zg9pjf0.fsf@gnu.org> From: Eli Zaretskii To: Federico Tedin In-reply-to: <877e0u9in7.fsf@gmail.com> (message from Federico Tedin on Mon, 10 Feb 2020 23:34:04 +0100) Subject: Re: bug#39555: [PATCH] Allow tempo-define-template to reassign tags to new templates References: <877e0u9in7.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 39555 Cc: 39555@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > From: Federico Tedin > Date: Mon, 10 Feb 2020 23:34:04 +0100 > > (This may apply as a bug and as a wishlist item at the same time - not sure) I think this should go to master in any case. Given that tempo.el is not actively maintained lately, I think you can install your changes, after taking care of the minor issues below. > -(defun tempo-invalidate-collection () > +(defun tempo-invalidate-collection (&optional global) > "Marks the tag collection as obsolete. > -Whenever it is needed again it will be rebuilt." > - (setq tempo-dirty-collection t)) > +Whenever it is needed again it will be rebuilt. When GLOBAL is ^^^^ Please use "if", not "when". That's our usual style of describing optional arguments. I think the API changes should be in NEWS. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Mon Feb 17 16:28:02 2020 Received: (at 39555) by debbugs.gnu.org; 17 Feb 2020 21:28:02 +0000 Received: from localhost ([127.0.0.1]:39318 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j3nvt-0005Rf-UC for submit@debbugs.gnu.org; Mon, 17 Feb 2020 16:28:02 -0500 Received: from mail-wr1-f48.google.com ([209.85.221.48]:37840) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j3nvr-0005RL-Hs for 39555@debbugs.gnu.org; Mon, 17 Feb 2020 16:28:00 -0500 Received: by mail-wr1-f48.google.com with SMTP id w15so21467821wru.4 for <39555@debbugs.gnu.org>; Mon, 17 Feb 2020 13:27:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=lFxp3N82UqMV2CR67gm5dAt6FjiOEiEhGflHM+L3TmQ=; b=AbIA0cJUTVZ/sdKbgDp4OFMNbb/U70+y+1XVdOHLuxqqcl81OvezT1virgPFJVE+pZ w7YausqDmcX8bKKFepc6aOCESSDMVE9zSVNvLh33lxRNknu7kzuD1bC3KoelW6FyKpfm Xl9gbgUw9IewpIe/Mp5kPv3O5Z0BDEbhpo5iEVby4xw34K5VPgy7vruuO7cuzgTluLla ovWrZMk+x4/Xof6TyjTm0SI9IcS8xgVECenaaLypWJAiAzZ7NTa2N+N0QNm+TvX+46g4 kctQ9VUNW8STfboe2U+hHX1taZEQZX83/ILKJRR7zST31p8w0cqWlTgVxKdGZeWGl6hB Hr8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=lFxp3N82UqMV2CR67gm5dAt6FjiOEiEhGflHM+L3TmQ=; b=qbs2EJY1ZeQgInk6tWx39LUSdAissVNppL7ebGY3RBngr8w1OuOBmvn5dalvSmqcAS anqFh4kImjZ2XEKs1CzYjwm4WWKwF88VEE+LIufIGSFbLiXtKAK9t726cUYzdCHa6NU3 29WC3SHVpT/9zapx4gBKvOmMHs5L9S6GahJkconlH4ctGk9V3znt0sZlwJrU1eTH/r2S iaAeXytktwsapUHeapzDMdmFoS0VfBraElDEJbPvLsCsxVVAOgu8vtd6BHkIo+0TuYly cE+h6qyPux9L5BoN4+4+aqzMicJRTkWYr90gIUGBHpWgzYwg1vt9/ZUj6RIkYi+pDCYZ oStg== X-Gm-Message-State: APjAAAVqkBRvO5ttXOIOTOhYVhgwdu6NmtildEEKTt82OXrN8QSkYo6S rK9cgePVPjLzf3RBQx2u2oKzyxLdcVc= X-Google-Smtp-Source: APXvYqzg2T4qgAPKwkvKebTDZJqRPqkELubP1EehrO02tOkVaO6jcBHTjXu629MB0D1Vw4MciKSbmg== X-Received: by 2002:adf:f58c:: with SMTP id f12mr23176236wro.22.1581974873316; Mon, 17 Feb 2020 13:27:53 -0800 (PST) Received: from BERMB00016 ([2a02:8109:8ac0:2ff0:e051:7ad2:2a71:fe3c]) by smtp.gmail.com with ESMTPSA id c4sm898606wml.7.2020.02.17.13.27.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 17 Feb 2020 13:27:52 -0800 (PST) From: Federico Tedin To: Eli Zaretskii Subject: Re: bug#39555: [PATCH] Allow tempo-define-template to reassign tags to new templates References: <877e0u9in7.fsf@gmail.com> <835zg9pjf0.fsf@gnu.org> Date: Mon, 17 Feb 2020 22:27:51 +0100 In-Reply-To: <835zg9pjf0.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 14 Feb 2020 12:12:03 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 39555 Cc: 39555@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain > I think this should go to master in any case. > > Given that tempo.el is not actively maintained lately, I think you can > install your changes, after taking care of the minor issues below. > >> -(defun tempo-invalidate-collection () >> +(defun tempo-invalidate-collection (&optional global) >> "Marks the tag collection as obsolete. >> -Whenever it is needed again it will be rebuilt." >> - (setq tempo-dirty-collection t)) >> +Whenever it is needed again it will be rebuilt. When GLOBAL is > ^^^^ > Please use "if", not "when". That's our usual style of describing > optional arguments. > > I think the API changes should be in NEWS. > > Thanks. No problem, I'm attaching a new patch with those corrections applied. - Fede --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-tempo-define-template-to-reassign-tags-to-new-.patch >From 5dc2c0a4674177b04302e0cc3d90a1177817feab Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Mon, 17 Feb 2020 22:24:40 +0100 Subject: [PATCH] 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. --- etc/NEWS | 8 ++++++++ lisp/tempo.el | 31 +++++++++++++++++++++++-------- test/lisp/tempo-tests.el | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 1f8e6049a8..17992d541a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -126,6 +126,14 @@ supplied error message. *** New connection method "media", which allows accessing media devices like cell phones, tablets or cameras. +** Tempo + +--- +*** 'tempo-define-template' can now re-assign templates to tags. +Previously, assigning a new template to an already defined tag had no +effect. + + ** map.el *** Pcase 'map' pattern added keyword symbols abbreviation. diff --git a/lisp/tempo.el b/lisp/tempo.el index 9de5ac66c7..2da90f08c8 100644 --- a/lisp/tempo.el +++ b/lisp/tempo.el @@ -220,7 +220,9 @@ tempo-define-template DOCUMENTATION is the documentation string for the insertion command created, and TAGLIST (a symbol) is the tag list that TAG (if provided) should be added to. If TAGLIST is nil and TAG is non-nil, TAG is -added to `tempo-tags'. +added to `tempo-tags'. If TAG already corresponds to a template in +the tag list, modify the list so that TAG now corresponds to the newly +defined template. The elements in ELEMENTS can be of several types: @@ -579,14 +581,20 @@ tempo-backward-mark (defun tempo-add-tag (tag template &optional tag-list) "Add a template tag. Add the TAG, that should complete to TEMPLATE to the list in TAG-LIST, -or to `tempo-tags' if TAG-LIST is nil." +or to `tempo-tags' if TAG-LIST is nil. If TAG was already in the list, +replace its template with TEMPLATE." (interactive "sTag: \nCTemplate: ") (if (null tag-list) (setq tag-list 'tempo-tags)) - (if (not (assoc tag (symbol-value tag-list))) - (set tag-list (cons (cons tag template) (symbol-value tag-list)))) - (tempo-invalidate-collection)) + (let ((entry (assoc tag (symbol-value tag-list)))) + (if entry + ;; Tag is already in the list, assign a new template to it + (setcdr entry template) + ;; Tag is not present in the list, add it with its template + (set tag-list (cons (cons tag template) (symbol-value tag-list))))) + ;; Invalidate globally if we're modifying `tempo-tags' + (tempo-invalidate-collection (eq tag-list 'tempo-tags))) ;;; ;;; tempo-use-tag-list @@ -609,10 +617,17 @@ tempo-use-tag-list ;;; ;;; tempo-invalidate-collection -(defun tempo-invalidate-collection () +(defun tempo-invalidate-collection (&optional global) "Marks the tag collection as obsolete. -Whenever it is needed again it will be rebuilt." - (setq tempo-dirty-collection t)) +Whenever it is needed again it will be rebuilt. If GLOBAL is non-nil, +mark the tag collection of all buffers as obsolete, not just the +current one." + (if global + (dolist (buffer (buffer-list)) + (with-current-buffer buffer + (when (assq 'tempo-dirty-collection (buffer-local-variables)) + (setq tempo-dirty-collection t)))) + (setq tempo-dirty-collection t))) ;;; ;;; tempo-build-collection diff --git a/test/lisp/tempo-tests.el b/test/lisp/tempo-tests.el index 0dd310b853..bfe475910d 100644 --- a/test/lisp/tempo-tests.el +++ b/test/lisp/tempo-tests.el @@ -216,6 +216,45 @@ tempo-expand-tag-test (tempo-complete-tag) (should (equal (buffer-string) "Hello, World!")))) +(ert-deftest tempo-define-tag-globally-test () + "Testing usage of a template tag defined from another buffer." + (tempo-define-template "test" '("Hello, World!") "hello") + + (with-temp-buffer + ;; Use a tag in buffer 1 + (insert "hello") + (tempo-complete-tag) + (should (equal (buffer-string) "Hello, World!")) + (erase-buffer) + + ;; Collection should not be dirty + (should-not tempo-dirty-collection) + + ;; Define a tag on buffer 2 + (with-temp-buffer + (tempo-define-template "test2" '("Now expanded.") "mytag")) + + ;; I should be able to use this template back in buffer 1 + (insert "mytag") + (tempo-complete-tag) + (should (equal (buffer-string) "Now expanded.")))) + +(ert-deftest tempo-overwrite-tag-test () + "Testing ability to reassign templates to tags." + (with-temp-buffer + ;; Define a tag and use it + (tempo-define-template "test-tag-1" '("abc") "footag") + (insert "footag") + (tempo-complete-tag) + (should (equal (buffer-string) "abc")) + (erase-buffer) + + ;; Define a new template with the same tag + (tempo-define-template "test-tag-2" '("xyz") "footag") + (insert "footag") + (tempo-complete-tag) + (should (equal (buffer-string) "xyz")))) + (ert-deftest tempo-expand-partial-tag-test () "Testing expansion of a template with a tag, with a partial match." (with-temp-buffer -- 2.21.1 (Apple Git-122.3) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 21 04:20:59 2020 Received: (at 39555-done) by debbugs.gnu.org; 21 Feb 2020 09:20:59 +0000 Received: from localhost ([127.0.0.1]:46392 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j54UU-0004cK-TM for submit@debbugs.gnu.org; Fri, 21 Feb 2020 04:20:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j54UT-0004c7-97 for 39555-done@debbugs.gnu.org; Fri, 21 Feb 2020 04:20:57 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:45569) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1j54UO-0007CW-5q; Fri, 21 Feb 2020 04:20:52 -0500 Received: from [176.228.60.248] (port=2107 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1j54UN-0003qE-9W; Fri, 21 Feb 2020 04:20:51 -0500 Date: Fri, 21 Feb 2020 11:20:40 +0200 Message-Id: <83ftf4jnyv.fsf@gnu.org> From: Eli Zaretskii To: Federico Tedin In-reply-to: (message from Federico Tedin on Mon, 17 Feb 2020 22:27:51 +0100) Subject: Re: bug#39555: [PATCH] Allow tempo-define-template to reassign tags to new templates References: <877e0u9in7.fsf@gmail.com> <835zg9pjf0.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 39555-done Cc: 39555-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > From: Federico Tedin > Cc: 39555@debbugs.gnu.org > Date: Mon, 17 Feb 2020 22:27:51 +0100 > > No problem, I'm attaching a new patch with those corrections applied. Thanks, pushed to the master branch. Please see my follow-up commit with minor punctuation fixes. Also, please try to always mention in the log message the bug number when it's known (this is impossible if your original message that opens a bug report already includes the patch, but it _is_ possible when you post additional versions to the same bug report). From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 21 14:47:11 2020 Received: (at 39555-done) by debbugs.gnu.org; 21 Feb 2020 19:47:11 +0000 Received: from localhost ([127.0.0.1]:48169 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j5EGV-0001NX-54 for submit@debbugs.gnu.org; Fri, 21 Feb 2020 14:47:11 -0500 Received: from mail-wm1-f44.google.com ([209.85.128.44]:51267) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1j5EGT-0001NK-78 for 39555-done@debbugs.gnu.org; Fri, 21 Feb 2020 14:47:09 -0500 Received: by mail-wm1-f44.google.com with SMTP id t23so2986736wmi.1 for <39555-done@debbugs.gnu.org>; Fri, 21 Feb 2020 11:47:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=HFq0CSXmG5SofA4B9NniAWuGbbVmPJcidrR+4KzLsxY=; b=T7Z9/6UJu5WtFeZ2p/IVaWMU051wU2fPqZnZ127fSEOWiv3Yo+y5W01NI1EFFfOzV3 lorkZ81ZE576KuhTz4/WnPFOCLR8Wt2ZAFKSLI1UmmbL2Ojhj7bo9ajUbMTxBNjc0zjB HH8xVjcPMEMaHx4C57aYwhAQX61pOpPgNAnlk6loufdQ3D6zS70b06Y1/JStiPShuzld xD0xh9n6VtfHe9rcv4nZnV+HZlXcryHRUuBQx7gpBT6n2L7y5TweiQ+71byWwD9CuMAJ ajsqQVoV9JbvnRKLbW90T2TkFN9raAGAvT3DtLaCETQgUgnrF0rsKh+1djX/dHUTmEa5 tH2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=HFq0CSXmG5SofA4B9NniAWuGbbVmPJcidrR+4KzLsxY=; b=TQKtzPrhwU4VLjyL0hUWMcMqXSCsk5CsjXUUcQskZ8lfBg+uJSRx27YKKN/6R16nf8 8AEoWG4yvwpvvoDEeciEYjIsRbm3dQ6RRBQuPmlXkOwOWgONgV8qKT4SvNcq67Hv0NwK qedY7jHVYh0NDX0zVxbpONCvfvHFJayfmWiO+pv1fUdS1cEwYsJqHQ3h0PYyluQjuubp ymVPVZyqlWHwXkHb+Z6GP4OOXLw3QDT1T/5H2F2cNPw5OHdTW2PU3/R9XGYxZtgtVV4H /pmohQN7q/7XDN3WvbH3FUhKY+VLvKCop62U7UcxSebFK3o7h8lA8oDBgQTkM/DbA2qr 3Uwg== X-Gm-Message-State: APjAAAXErYAP5OE8aY+aAA6+5Wu4fIpR7d1eBYh6AVl3tdjnnpuN5VBO VAqR+vvtbDVxSraiG6kV2E0scso0Xtk= X-Google-Smtp-Source: APXvYqz7r5CpiegkzhL2U03/pWb+qzLIODIV7+SmiOw3YXhAAx1dqUabtUqe/dKFbgX+aT1lkf/4uw== X-Received: by 2002:a7b:c957:: with SMTP id i23mr5540700wml.174.1582314422949; Fri, 21 Feb 2020 11:47:02 -0800 (PST) Received: from BERMB00016 ([2a02:8109:8ac0:2ff0:85c8:39c1:ac0c:741a]) by smtp.gmail.com with ESMTPSA id f8sm4955467wru.12.2020.02.21.11.47.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Feb 2020 11:47:02 -0800 (PST) From: Federico Tedin X-Google-Original-From: Federico Tedin To: Eli Zaretskii Subject: Re: bug#39555: [PATCH] Allow tempo-define-template to reassign tags to new templates References: <877e0u9in7.fsf@gmail.com> <835zg9pjf0.fsf@gnu.org> <83ftf4jnyv.fsf@gnu.org> Date: Fri, 21 Feb 2020 20:47:01 +0100 In-Reply-To: <83ftf4jnyv.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 21 Feb 2020 11:20:40 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 39555-done Cc: 39555-done@debbugs.gnu.org, Federico Tedin X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: >> From: Federico Tedin >> Cc: 39555@debbugs.gnu.org >> Date: Mon, 17 Feb 2020 22:27:51 +0100 >> >> No problem, I'm attaching a new patch with those corrections applied. > > Thanks, pushed to the master branch. > > Please see my follow-up commit with minor punctuation fixes. Also, > please try to always mention in the log message the bug number when > it's known (this is impossible if your original message that opens a > bug report already includes the patch, but it _is_ possible when you > post additional versions to the same bug report). Noted! Thanks. From unknown Sat Jun 14 18:52:40 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 21 Mar 2020 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator