Be more consistent about treating tags as case-sensitive

* lisp/org-agenda.el (org-agenda-finalize):
(org-agenda-format-item): Do not downcase tags.
(org-downcase-keep-props): Remove unused function.
(org-agenda-filter-expand-tags): Do not case-fold search.

* lisp/org.el (org-tags-expand): Document `downcased' argument as
obsolete and do not allow to expand downcased tags.

* testing/lisp/test-org.el (test-org/tags-expand): Remove test for
downcased tags expansion.

* doc/org-manual.org (TODO keywords, tags, properties, etc.):
Suggest that user-defined are usually lowercase, but don't make it
a requirement.

Reported-by: David Masterson <dsmasterson92630@outlook.com>
Link: https://orgmode.org/list/SJ0PR03MB5455D8D0C4F71AA495A9ABF79B709@SJ0PR03MB5455.namprd03.prod.outlook.com/
This commit is contained in:
Bastien Guerry 2021-04-27 09:41:26 +02:00
parent 26d1d29cf9
commit 13a1a4fb96
4 changed files with 11 additions and 28 deletions

View File

@ -344,7 +344,7 @@ conventions:
- =boss=, =ARCHIVE= :: - =boss=, =ARCHIVE= ::
Tags are case-sensitive. User-defined tags are written in Tags are case-sensitive. User-defined tags are usually written in
lowercase; built-in tags with special meaning are written as they lowercase; built-in tags with special meaning are written as they
should appear in the document, usually with all capitals. should appear in the document, usually with all capitals.

View File

@ -3919,7 +3919,7 @@ agenda display, configure `org-agenda-finalize-hook'."
(put-text-property (point-at-bol) (point-at-eol) (put-text-property (point-at-bol) (point-at-eol)
'tags 'tags
(org-with-point-at mrk (org-with-point-at mrk
(mapcar #'downcase (org-get-tags))))))))) (org-get-tags))))))))
(setq org-agenda-represented-tags nil (setq org-agenda-represented-tags nil
org-agenda-represented-categories nil) org-agenda-represented-categories nil)
(when org-agenda-top-headline-filter (when org-agenda-top-headline-filter
@ -6731,7 +6731,7 @@ Any match of REMOVE-RE will be removed from TXT."
(remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn) (remove-text-properties 0 (length rtn) '(line-prefix t wrap-prefix t) rtn)
(org-add-props rtn nil (org-add-props rtn nil
'org-category category 'org-category category
'tags (mapcar 'org-downcase-keep-props tags) 'tags tags
'org-priority-highest org-priority-highest 'org-priority-highest org-priority-highest
'org-priority-lowest org-priority-lowest 'org-priority-lowest org-priority-lowest
'time-of-day time-of-day 'time-of-day time-of-day
@ -6776,12 +6776,6 @@ The modified list may contain inherited tags, and tags matched by
(if have-i "::" ":")))))) (if have-i "::" ":"))))))
txt) txt)
(defun org-downcase-keep-props (s)
(let ((props (text-properties-at 0 s)))
(setq s (downcase s))
(add-text-properties 0 (length s) props s)
s))
(defvar org-agenda-sorting-strategy) ;; because the def is in a let form (defvar org-agenda-sorting-strategy) ;; because the def is in a let form
(defun org-agenda-add-time-grid-maybe (list ndays todayp) (defun org-agenda-add-time-grid-maybe (list ndays todayp)
@ -8074,7 +8068,7 @@ If the line does not have an effort defined, return nil."
When NO-OPERATOR is non-nil, do not add the + operator to When NO-OPERATOR is non-nil, do not add the + operator to
returned tags." returned tags."
(if org-group-tags (if org-group-tags
(let ((case-fold-search t) rtn) (let (case-fold-search rtn)
(mapc (mapc
(lambda (f) (lambda (f)
(let (f0 dir) (let (f0 dir)
@ -8082,7 +8076,7 @@ returned tags."
(setq dir (match-string 1 f) f0 (match-string 2 f)) (setq dir (match-string 1 f) f0 (match-string 2 f))
(setq dir (if no-operator "" "+") f0 f)) (setq dir (if no-operator "" "+") f0 f))
(setq rtn (append (mapcar (lambda(f1) (concat dir f1)) (setq rtn (append (mapcar (lambda(f1) (concat dir f1))
(org-tags-expand f0 t t)) (org-tags-expand f0 t))
rtn)))) rtn))))
filter) filter)
(reverse rtn)) (reverse rtn))

View File

@ -11760,22 +11760,18 @@ When the optional argument SINGLE-AS-LIST is non-nil, MATCH is
assumed to be a single group tag, and the function will return assumed to be a single group tag, and the function will return
the list of tags in this group. the list of tags in this group.
When DOWNCASED is non-nil, expand downcased TAGS." The DOWNCASED argument is obsolete and has no effect."
(unless (org-string-nw-p match) (error "Invalid match tag: %S" match)) (unless (org-string-nw-p match) (error "Invalid match tag: %S" match))
(let ((tag-groups (let ((tag-groups
(let ((g (or org-tag-groups-alist-for-agenda org-tag-groups-alist))) (or org-tag-groups-alist-for-agenda org-tag-groups-alist)))
(if (not downcased) g
(mapcar (lambda (s) (mapcar #'downcase s)) g)))))
(cond (cond
(single-as-list (org--tags-expand-group (single-as-list (org--tags-expand-group (list match) tag-groups nil))
(list (if downcased (downcase match) match))
tag-groups nil))
(org-group-tags (org-group-tags
(let* ((case-fold-search t) (let* ((case-fold-search t)
(tag-syntax org-mode-syntax-table) (tag-syntax org-mode-syntax-table)
(group-keys (mapcar #'car tag-groups)) (group-keys (mapcar #'car tag-groups))
(key-regexp (concat "\\([+-]?\\)" (regexp-opt group-keys 'words))) (key-regexp (concat "\\([+-]?\\)" (regexp-opt group-keys 'words)))
(return-match (if downcased (downcase match) match))) (return-match match))
;; Mark regexp-expressions in the match-expression so that we ;; Mark regexp-expressions in the match-expression so that we
;; do not replace them later on. ;; do not replace them later on.
(let ((s 0)) (let ((s 0))
@ -11795,7 +11791,7 @@ When DOWNCASED is non-nil, expand downcased TAGS."
m ;regexp tag: ignore m ;regexp tag: ignore
(let* ((operator (match-string 1 m)) (let* ((operator (match-string 1 m))
(tag-token (let ((tag (match-string 2 m))) (tag-token (let ((tag (match-string 2 m)))
(list (if downcased (downcase tag) tag)))) (list tag)))
regexp-tags regular-tags) regexp-tags regular-tags)
;; Partition tags between regexp and regular tags. ;; Partition tags between regexp and regular tags.
;; Remove curly bracket syntax from regexp tags. ;; Remove curly bracket syntax from regexp tags.

View File

@ -7172,14 +7172,7 @@ Paragraph<point>"
(equal "{A+}" (equal "{A+}"
(org-test-with-temp-text "#+TAGS: [ A : B C ]" (org-test-with-temp-text "#+TAGS: [ A : B C ]"
(org-mode-restart) (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 ;;; TODO keywords