From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: [PATCH] Ensure org-get-tags includes all local tags Date: Wed, 25 Jul 2018 07:57:54 -0500 Message-ID: <87r2jrsca5.fsf@fastmail.fm> References: <878t7tm8tf.fsf@fastmail.fm> <87d0x56prn.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiJMg-0004uc-6G for emacs-orgmode@gnu.org; Wed, 25 Jul 2018 08:58:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiJMd-0001Cp-8k for emacs-orgmode@gnu.org; Wed, 25 Jul 2018 08:58:02 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:56901) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fiJMc-0001Bz-Vq for emacs-orgmode@gnu.org; Wed, 25 Jul 2018 08:57:59 -0400 In-Reply-To: <87d0x56prn.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 05 Jun 2018 20:40:12 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: Org Mode --=-=-= Content-Type: text/plain >> With commit fbe56f89f75a8979e0ba48001a822518df2c66fe, the function >> org-get-tags incorrectly removes uninherited tags from the list of tags >> it returns, *even if* they are local tags. >> >> Expected behavior: org-get-tags should always return local tags, >> regardless of whether they are excluded from inheritance. The variable >> org-tags-exclude-from-inheritance should only apply to tags in parent >> heading or to file tags. >> >> Actual behavior: if a local tag is in org-tags-exclude-from-inheritance, >> org-get-tags will not return it. >> >> I've attached a patch that fixes the issue. > > You're right. Thank you. > > Could you add a regression test for this and push the change? > Hi Nicolas, Sorry for the delay. I finally had time to improve this fix (my first fix caused another regression) and add a regression test. At the moment, I don't have push rights to the Org Mode repo, so I'm attaching the patch here. Best, Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Ensure-that-org-get-tags-returns-all-local-tags.patch >From f3dc39236e8f3940c58ab4e48f629360028131e1 Mon Sep 17 00:00:00 2001 From: Matt Lundin Date: Wed, 25 Jul 2018 07:48:10 -0500 Subject: [PATCH] Ensure that org-get-tags returns all local tags * lisp/org.el: (org-get-tags) Create a clearer separation between local and inherited tags in the function, so that org-remove-uninherited tags is only run on inherited tags. This is important to avoid destroying existing tags when adding new tags. * testing/lisp/test-org.el: (test-org/get-tags) Add regression test --- lisp/org.el | 15 ++++++++------- testing/lisp/test-org.el | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 999575d05..94252489c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -14722,14 +14722,15 @@ Inherited tags have the `inherited' text property." (org-with-point-at (or pos (point)) (unless (org-before-first-heading-p) (org-back-to-heading t) - (let ((tags (org--get-local-tags))) - (if (or local (not org-use-tag-inheritance)) tags + (let ((ltags (org--get-local-tags)) itags) + (if (or local (not org-use-tag-inheritance)) ltags + (setq itags org-file-tags) (while (org-up-heading-safe) - (setq tags (append (mapcar #'org-add-prop-inherited - (org--get-local-tags)) - tags))) - (org-remove-uninherited-tags - (delete-dups (append org-file-tags tags))))))))) + (setq itags (append (mapcar #'org-add-prop-inherited + (org--get-local-tags)) + itags))) + (delete-dups + (append (org-remove-uninherited-tags itags) ltags)))))))) (defun org-get-buffer-tags () "Get a table of all tags used in the buffer, for completion." diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index a6b283163..20164beb5 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -6190,6 +6190,13 @@ Paragraph" (equal '("foo") (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:" (org-get-tags 1)))) + ;; Make sure tags excluded from inheritance are returned if local + (should + (equal '("foo") + (org-test-with-temp-text "* Test :foo:" + (let ((org-use-tag-inheritance t) + (org-tags-exclude-from-inheritance '("foo"))) + (org-get-tags))))) ;; Pathological case: tagged headline with an empty body. (should (org-test-with-temp-text "* :tag:" (org-get-tags)))) -- 2.18.0 --=-=-=--