Fix element property queries for inlinetasks

* lisp/org.el (org-get-tags): Do not ignore local tags in inlinetasks.
(org-in-commented-heading-p): Do not ignore commented inlinetasks.
* testing/lisp/test-org.el (test-org/get-tags): Add tests for
inlinetasks.

Fixes https://list.orgmode.org/CAKJdtO8-KkVvhcviTqhi+DMZmSK=o37jn1jJPM9qxcuXZPnGgw@mail.gmail.com/T/#u
This commit is contained in:
Ihor Radchenko 2021-11-22 19:26:26 +08:00
parent cd3e138ee5
commit 7a14d6035c
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 41 additions and 28 deletions

View File

@ -12629,34 +12629,34 @@ Inherited tags have the `inherited' text property."
(not local)) (not local))
org-scanner-tags org-scanner-tags
(org-with-point-at (unless (org-element-type pos-or-element) (org-with-point-at (unless (org-element-type pos-or-element)
(or pos-or-element (point))) (or pos-or-element (point)))
(unless (and (not (org-element-type pos-or-element)) (unless (or (org-element-type pos-or-element)
(org-before-first-heading-p)) (org-before-first-heading-p))
(unless (org-element-type pos-or-element) (org-back-to-heading t)) (org-back-to-heading t))
(let ((ltags (if (org-element-type pos-or-element) (let ((ltags (if (org-element-type pos-or-element)
(org-element-property :tags (org-element-lineage pos-or-element '(headline) t)) (org-element-property :tags (org-element-lineage pos-or-element '(headline inlinetask) t))
(org--get-local-tags))) (org--get-local-tags)))
itags) itags)
(if (or local (not org-use-tag-inheritance)) ltags (if (or local (not org-use-tag-inheritance)) ltags
(let ((cached (and (org-element--cache-active-p) (let ((cached (and (org-element--cache-active-p)
(if (org-element-type pos-or-element) (if (org-element-type pos-or-element)
(org-element-lineage pos-or-element '(headline) t) (org-element-lineage pos-or-element '(headline org-data inlinetask) t)
(org-element-at-point nil 'cached))))) (org-element-at-point nil 'cached)))))
(if cached (if cached
(while (setq cached (org-element-property :parent cached)) (while (setq cached (org-element-property :parent cached))
(setq itags (nconc (mapcar #'org-add-prop-inherited
;; If we do not wrap result into `cl-copy-list', reference would
;; be returned and cache element might be modified directly.
(cl-copy-list (org-element-property :tags cached)))
itags)))
(while (org-up-heading-safe)
(setq itags (nconc (mapcar #'org-add-prop-inherited (setq itags (nconc (mapcar #'org-add-prop-inherited
(org--get-local-tags)) ;; If we do not wrap result into `cl-copy-list', reference would
itags))))) ;; be returned and cache element might be modified directly.
(setq itags (append org-file-tags itags)) (cl-copy-list (org-element-property :tags cached)))
(nreverse itags)))
(delete-dups (while (org-up-heading-safe)
(nreverse (nconc (org-remove-uninherited-tags itags) ltags))))))))))) (setq itags (nconc (mapcar #'org-add-prop-inherited
(org--get-local-tags))
itags)))))
(setq itags (append org-file-tags itags))
(nreverse
(delete-dups
(nreverse (nconc (org-remove-uninherited-tags itags) ltags))))))))))
(defun org-get-buffer-tags () (defun org-get-buffer-tags ()
"Get a table of all tags used in the buffer, for completion." "Get a table of all tags used in the buffer, for completion."
@ -20735,7 +20735,7 @@ Optional argument ELEMENT contains element at point."
(let ((el (or element (org-element-at-point nil 'cached)))) (let ((el (or element (org-element-at-point nil 'cached))))
(if el (if el
(catch :found (catch :found
(setq el (org-element-lineage el '(headline) 'include-self)) (setq el (org-element-lineage el '(headline inlinetask) 'include-self))
(if no-inheritance (if no-inheritance
(org-element-property :commentedp el) (org-element-property :commentedp el)
(while el (while el

View File

@ -6788,6 +6788,19 @@ Paragraph<point>"
(should (should
(equal '("foo" "bar") (equal '("foo" "bar")
(org-test-with-temp-text "* Test :foo:bar:" (org-get-tags)))) (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
;; Tags for inlinetasks.
(should
(equal '("foo" "bar")
(progn
(require 'org-inlinetask)
(org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
(org-get-tags (org-element-at-point))))))
(should
(equal '("foo" "bar")
(progn
(require 'org-inlinetask)
(org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
(org-get-tags nil)))))
;; Return nil when there is no tag. ;; Return nil when there is no tag.
(should-not (should-not
(org-test-with-temp-text "* Test" (org-get-tags))) (org-test-with-temp-text "* Test" (org-get-tags)))