Browse Source

org-tags-expand: Fix handling of downcased group tags

* lisp/org.el (org-tags-expand): Support using an upper- or mix-case
tag as MATCH when SINGLE-AS-LIST and DOWNCASED are non-nil, fixing a
regression from v9.2.
* testing/lisp/test-org.el (test-org/tags-expand): Add test.

org-agenda-filter-by-tag reads a case-sensitive tag from the user, and
downstream code passes this tag as is to org-tags-expand along with
non-nil values for SINGLE-AS-LIST and DOWNCASED.  As of 9df82be07 (Fix
tag groups expansion as a regexp, 2018-11-08), org-tags-expand fails
to return the group tags in this scenario for queries that contains an
uppercase letter, breaking org-agenda-filter-by-tag.

Downcase MATCH if SINGLE-AS-LIST and DOWNCASED are non-nil.

Reported-by: Leon Weber <leon.weber@net2.ch>
Ref: https://orgmode.org/list/c1f8cc32-dc16-697c-c24d-e5e05124bd66@net2.ch
Kyle Meyer 4 years ago
parent
commit
6676a97d27
2 changed files with 11 additions and 2 deletions
  1. 3 1
      lisp/org.el
  2. 8 1
      testing/lisp/test-org.el

+ 3 - 1
lisp/org.el

@@ -11742,7 +11742,9 @@ When DOWNCASED is non-nil, expand downcased TAGS."
 	   (if (not downcased) g
 	     (mapcar (lambda (s) (mapcar #'downcase s)) g)))))
     (cond
-     (single-as-list (org--tags-expand-group (list match) tag-groups nil))
+     (single-as-list (org--tags-expand-group
+		      (list (if downcased (downcase match) match))
+		      tag-groups nil))
      (org-group-tags
       (let* ((case-fold-search t)
 	     (tag-syntax org-mode-syntax-table)

+ 8 - 1
testing/lisp/test-org.el

@@ -7106,7 +7106,14 @@ Paragraph<point>"
    (equal "{A+}"
 	  (org-test-with-temp-text "#+TAGS: [ A : B C ]"
 	    (org-mode-restart)
-	    (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
+	    (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}")))))
+  ;; Uppercase MATCH works with a non-nil DOWNCASED and SINGLE-AS-LIST.
+  (should
+   (equal (list "a" "b" "c")
+	  (org-test-with-temp-text "#+TAGS: [ A : B C ]"
+	    (org-mode-restart)
+	    (let ((org-tag-alist-for-agenda nil))
+	      (sort (org-tags-expand "A" t t) #'string-lessp))))))
 
 
 ;;; TODO keywords