From 7a14d6035cdaa135671695fced8431aa26cb5e9d Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Mon, 22 Nov 2021 19:26:26 +0800 Subject: [PATCH] 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 --- lisp/org.el | 56 ++++++++++++++++++++-------------------- testing/lisp/test-org.el | 13 ++++++++++ 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 331bd9f65..df3d139c7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -12629,34 +12629,34 @@ Inherited tags have the `inherited' text property." (not local)) org-scanner-tags (org-with-point-at (unless (org-element-type pos-or-element) - (or pos-or-element (point))) - (unless (and (not (org-element-type pos-or-element)) - (org-before-first-heading-p)) - (unless (org-element-type pos-or-element) (org-back-to-heading t)) - (let ((ltags (if (org-element-type pos-or-element) - (org-element-property :tags (org-element-lineage pos-or-element '(headline) t)) - (org--get-local-tags))) - itags) - (if (or local (not org-use-tag-inheritance)) ltags - (let ((cached (and (org-element--cache-active-p) - (if (org-element-type pos-or-element) - (org-element-lineage pos-or-element '(headline) t) - (org-element-at-point nil 'cached))))) - (if 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) + (or pos-or-element (point))) + (unless (or (org-element-type pos-or-element) + (org-before-first-heading-p)) + (org-back-to-heading t)) + (let ((ltags (if (org-element-type pos-or-element) + (org-element-property :tags (org-element-lineage pos-or-element '(headline inlinetask) t)) + (org--get-local-tags))) + itags) + (if (or local (not org-use-tag-inheritance)) ltags + (let ((cached (and (org-element--cache-active-p) + (if (org-element-type pos-or-element) + (org-element-lineage pos-or-element '(headline org-data inlinetask) t) + (org-element-at-point nil 'cached))))) + (if cached + (while (setq cached (org-element-property :parent cached)) (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))))))))))) + ;; 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 + (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 () "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)))) (if el (catch :found - (setq el (org-element-lineage el '(headline) 'include-self)) + (setq el (org-element-lineage el '(headline inlinetask) 'include-self)) (if no-inheritance (org-element-property :commentedp el) (while el diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 5838b192d..73e9afcbd 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -6788,6 +6788,19 @@ Paragraph" (should (equal '("foo" "bar") (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. (should-not (org-test-with-temp-text "* Test" (org-get-tags)))