emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Ensure org-get-tags includes all local tags
@ 2018-06-05 17:39 Matt Lundin
  2018-06-05 18:40 ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Lundin @ 2018-06-05 17:39 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 799 bytes --]

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.

This causes problems with functions that call org-get-tags. For
instance, if org-fast-tag-selection-single-key is set,
org-set-tags-command delete all local tags that are in the list
org-tags-exclude-from-inheritance.

I've attached a patch that fixes the issue.

Best,

Matt


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Ensure-org-get-tags-returns-all-local-tags.patch --]
[-- Type: text/x-patch, Size: 988 bytes --]

From 407c9c88f7c8629ae99fed5060ef2c428b54ebd8 Mon Sep 17 00:00:00 2001
From: Matt Lundin <mdl@imapmail.org>
Date: Tue, 5 Jun 2018 12:31:42 -0500
Subject: [PATCH] Ensure org-get-tags returns all local tags

* lisp/org.el: (org-get-tags) Fix a bug that removed local tags if
  they were in the org-tags-exclude-from-inheritance list.
---
 lisp/org.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index d2b4c26ff..8cfb64510 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -14713,8 +14713,8 @@ Inherited tags have the `inherited' text property."
 	      (setq tags (append (mapcar #'org-add-prop-inherited
 					 (org--get-local-tags))
 				 tags)))
-	    (org-remove-uninherited-tags
-	     (delete-dups (append org-file-tags tags)))))))))
+	    (delete-dups (append (org-remove-uninherited-tags org-file-tags)
+			  tags))))))))
 
 (defun org-get-buffer-tags ()
   "Get a table of all tags used in the buffer, for completion."
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Ensure org-get-tags includes all local tags
  2018-06-05 17:39 [PATCH] Ensure org-get-tags includes all local tags Matt Lundin
@ 2018-06-05 18:40 ` Nicolas Goaziou
  2018-07-25 12:57   ` Matt Lundin
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2018-06-05 18:40 UTC (permalink / raw)
  To: Org Mode

Hello,

Matt Lundin <mdl@imapmail.org> writes:

> 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.
>
> This causes problems with functions that call org-get-tags. For
> instance, if org-fast-tag-selection-single-key is set,
> org-set-tags-command delete all local tags that are in the list
> org-tags-exclude-from-inheritance.
>
> 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?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Ensure org-get-tags includes all local tags
  2018-06-05 18:40 ` Nicolas Goaziou
@ 2018-07-25 12:57   ` Matt Lundin
  2018-08-19  8:29     ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Lundin @ 2018-07-25 12:57 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 949 bytes --]

>> 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Ensure-that-org-get-tags-returns-all-local-tags.patch --]
[-- Type: text/x-patch, Size: 2451 bytes --]

From f3dc39236e8f3940c58ab4e48f629360028131e1 Mon Sep 17 00:00:00 2001
From: Matt Lundin <mdl@imapmail.org>
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<point>"
    (equal '("foo")
 	  (org-test-with-temp-text "* H1 :foo:\n* <point>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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Ensure org-get-tags includes all local tags
  2018-07-25 12:57   ` Matt Lundin
@ 2018-08-19  8:29     ` Nicolas Goaziou
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2018-08-19  8:29 UTC (permalink / raw)
  To: Org Mode

Hello,

Matt Lundin <mdl@imapmail.org> writes:

> 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.

Applied. Thank you.

I suggest to ask Bastien for push rights.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-19  8:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-05 17:39 [PATCH] Ensure org-get-tags includes all local tags Matt Lundin
2018-06-05 18:40 ` Nicolas Goaziou
2018-07-25 12:57   ` Matt Lundin
2018-08-19  8:29     ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).