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/)]

2020-08-23 Thread Kyle Meyer
Allen Li writes:

> Attached new patch

Thanks.  Applied in 76da93aa8, adding periods to the end of the
changelog entries.



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/)]

2020-08-22 Thread Allen Li
On Fri, Aug 21, 2020 at 8:39 AM Allen Li  wrote:
>
> Kyle Meyer  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
From 24c1c9c423cd92d307033d56ca07692a23eab089 Mon Sep 17 00:00:00 2001
From: Allen Li 
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"
 	  (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** b :foo:"
+	(cl-letf (((symbol-function 'completing-read)
+		   (lambda (prompt coll  pred req initial  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



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/)]

2020-08-21 Thread Allen Li
Kyle Meyer  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.

>
> -- >8 --
> diff --git a/lisp/org.el b/lisp/org.el
> index fb95590fc..3dac42b7b 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -12310,8 +12310,10 @@ (defun org-get-tags ( pos local)
>(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."



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/)]

2020-08-18 Thread Kyle Meyer
Thanks for the patch.

Allen Li writes:

> Example Org file:
>
> * Parent :foo:bar:baz:
> ** Child :foo:bar:spam:
>
> Invoking org-set-tags-command with point on Child prepopulates the
> minibuffer prompt with only the tags :spam:
>
> This is because org-get-tags doesn't distinguish between inherited only
> tags and inherited tags which are also explicitly set on a heading, so
> org-set-tags-command treats :foo:bar: as inherited only rather than also
> set locally on the heading.
>
> This is undesirable because having tags set directly on a heading has
> different semantics even if they are also inherited (e.g., the TAGS
> special property, or when headings will be refiled to a different
> location later).

I agree, that's undesirable and likely unintended.

> Subject: [PATCH] org.el: Don't exclude local tags that are also inherited
>
> * lisp/org.el (org-set-tags-command): Don't exclude local tags even if 
> inherited.
> ---
>  lisp/org.el | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

It'd be good to add something along the lines of your example as a case
in test-org/set-tags-command.

> diff --git a/lisp/org.el b/lisp/org.el
> index fb95590fc..49d7d24f2 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -11880,9 +11880,7 @@ in Lisp code use `org-set-tags' instead."
> (org-global-tags-completion-table
>  (org-agenda-files)))
>(or org-current-tag-alist (org-get-buffer-tags)
> -(current-tags
> - (cl-remove-if (lambda (tag) (get-text-property 0 'inherited 
> tag))
> -   all-tags))
> +(current-tags (org-get-tags nil t))
>  (inherited-tags
>   (cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited 
> tag))
> all-tags))

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?

-- >8 --
diff --git a/lisp/org.el b/lisp/org.el
index fb95590fc..3dac42b7b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -12310,8 +12310,10 @@ (defun org-get-tags ( pos local)
   (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."



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/)]

2020-08-18 Thread Allen Li

Example Org file:

* Parent :foo:bar:baz:
** Child :foo:bar:spam:

Invoking org-set-tags-command with point on Child prepopulates the
minibuffer prompt with only the tags :spam:

This is because org-get-tags doesn't distinguish between inherited only
tags and inherited tags which are also explicitly set on a heading, so
org-set-tags-command treats :foo:bar: as inherited only rather than also
set locally on the heading.

This is undesirable because having tags set directly on a heading has
different semantics even if they are also inherited (e.g., the TAGS
special property, or when headings will be refiled to a different
location later).

Attached patch.

>From 934d65537e46c68c10edbfa2d7140cebfe89d271 Mon Sep 17 00:00:00 2001
From: Allen Li 
Date: Tue, 18 Aug 2020 15:34:38 -0700
Subject: [PATCH] org.el: Don't exclude local tags that are also inherited

* lisp/org.el (org-set-tags-command): Don't exclude local tags even if inherited.
---
 lisp/org.el | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index fb95590fc..49d7d24f2 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11880,9 +11880,7 @@ in Lisp code use `org-set-tags' instead."
   (org-global-tags-completion-table
    (org-agenda-files)))
 			 (or org-current-tag-alist (org-get-buffer-tags)
-	   (current-tags
-		(cl-remove-if (lambda (tag) (get-text-property 0 'inherited tag))
-			  all-tags))
+	   (current-tags (org-get-tags nil t))
 	   (inherited-tags
 		(cl-remove-if-not (lambda (tag) (get-text-property 0 'inherited tag))
   all-tags))
-- 
2.28.0


Emacs  : GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22)
 of 2020-08-11
Package: Org mode version 9.3.7 (9.3.7-18-g093b47-elpaplus @ 
/home/ionasal/.emacs.d/elpa/org-plus-contrib-20200810/)