From: Allen Li <darkfeline@felesatra.moe>
To: Kyle Meyer <kyle@kyleam.com>
Cc: Org Mode List <emacs-orgmode@gnu.org>
Subject: Re: Bug: org-set-tags-command deletes inherited tags [9.3.7 (9.3.7-18-g093b47-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20200810/)]
Date: Sat, 22 Aug 2020 09:03:07 +0000 [thread overview]
Message-ID: <CADbSrJyqHC5ns1XrcA-zmhHrG_cZD2nHwvV-6u4mOpWc_Wk9qg@mail.gmail.com> (raw)
In-Reply-To: <805z9cxuje.fsf@felesatra.moe>
[-- Attachment #1: Type: text/plain, Size: 971 bytes --]
On Fri, Aug 21, 2020 at 8:39 AM Allen Li <darkfeline@felesatra.moe> wrote:
>
> Kyle Meyer <kyle@kyleam.com> writes:
>
> > That looks good as far as fixing the misbehavior you report. I wonder
> > though whether there's a deeper org-get-tags issue here worth
> > considering. Its documentation says
> >
> > ... the returned list of tags contains tags in this order: file
> > tags, tags inherited from parent headlines, local tags.
> >
> > But it's not specified what happens when a tag is both local and
> > inherited. The current implementation drops the local tag variant
> > through its delete-dups call:
> >
> > (delete-dups
> > (append (org-remove-uninherited-tags itags) ltags))
> >
> > I would have expected the local tag to get priority here. If that were
> > the case (e.g., something like below), that would also solve the issue
> > you describe.
> >
> > Thoughts?
>
> That sounds reasonable, let me prepare a new patch.
Attached new patch
[-- Attachment #2: 0001-org.el-Don-t-exclude-local-tags-that-are-also-inheri.patch --]
[-- Type: text/x-patch, Size: 3127 bytes --]
From 24c1c9c423cd92d307033d56ca07692a23eab089 Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Tue, 18 Aug 2020 15:34:38 -0700
Subject: [PATCH] org.el: Don't exclude local tags that are also inherited
This fixes a bug in set-tags-command excluding a tag that is both set
locally and inherited from the initial minibuffer input by modifying
org-get-tags to prefer keeping the locally set tag over the inherited
tag, as this behavior is more intuitive for org-get-tags anyway.
* lisp/org.el (org-get-tags): Keep local tags over inherited
* testing/lisp/test-org.el (test-org/set-tags-command): Add test
---
lisp/org.el | 14 ++++++++------
testing/lisp/test-org.el | 11 +++++++++++
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index fb95590fc..71dbc611e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -12290,7 +12290,8 @@ According to `org-use-tag-inheritance', tags may be inherited
from parent headlines, and from the whole document, through
`org-file-tags'. In this case, the returned list of tags
contains tags in this order: file tags, tags inherited from
-parent headlines, local tags.
+parent headlines, local tags. If a tag appears multiple times,
+only the most local tag is returned.
However, when optional argument LOCAL is non-nil, only return
tags specified at the headline.
@@ -12306,12 +12307,13 @@ Inherited tags have the `inherited' text property."
(let ((ltags (org--get-local-tags)) itags)
(if (or local (not org-use-tag-inheritance)) ltags
(while (org-up-heading-safe)
- (setq itags (append (mapcar #'org-add-prop-inherited
- (org--get-local-tags))
- itags)))
+ (setq itags (nconc (mapcar #'org-add-prop-inherited
+ (org--get-local-tags))
+ itags)))
(setq itags (append org-file-tags itags))
- (delete-dups
- (append (org-remove-uninherited-tags itags) ltags))))))))
+ (nreverse
+ (delete-dups
+ (nreverse (nconc (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 4f8c74539..6144a7af1 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -6953,6 +6953,17 @@ Paragraph<point>"
(let ((org-use-fast-tag-selection nil)
(org-tags-column 1))
(org-set-tags-command)))
+ (buffer-substring (point) (line-end-position)))))
+ ;; Handle tags both set locally and inherited.
+ (should
+ (equal "b :foo:"
+ (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
+ (cl-letf (((symbol-function 'completing-read)
+ (lambda (prompt coll &optional pred req initial &rest args)
+ initial)))
+ (let ((org-use-fast-tag-selection nil)
+ (org-tags-column 1))
+ (org-set-tags-command)))
(buffer-substring (point) (line-end-position))))))
(ert-deftest test-org/toggle-tag ()
--
2.28.0
next prev parent reply other threads:[~2020-08-22 9:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-18 22:42 Bug: org-set-tags-command deletes inherited tags [9.3.7 (9.3.7-18-g093b47-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20200810/)] Allen Li
2020-08-19 4:43 ` Kyle Meyer
2020-08-21 8:39 ` Allen Li
2020-08-22 9:03 ` Allen Li [this message]
2020-08-24 2:43 ` Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADbSrJyqHC5ns1XrcA-zmhHrG_cZD2nHwvV-6u4mOpWc_Wk9qg@mail.gmail.com \
--to=darkfeline@felesatra.moe \
--cc=emacs-orgmode@gnu.org \
--cc=kyle@kyleam.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).