>From c62cbd6ac6cf6a845703b3f7cfb64fa68e39079a Mon Sep 17 00:00:00 2001
From: Ihor Radchenko <yanta...@gmail.com>
Date: Wed, 9 Dec 2020 16:59:58 +0800
Subject: [PATCH] Fix org-in-archived-heading-p

* lisp/org.el (org-in-archived-heading-p): When called on a heading
with a tag containing org-archive-tag string as a substring, that
heading was incorrectly recognised as archived.  Changed matching
against the whole :tag1:tag2:...: string to matching against tag list
as returned by `org-get-tags'.
* testing/lisp/test-org.el (test-org/in-archived-heading-p): Add test
when one of the heading tags contains org-archive-tag as a substring.
---
Range-diff:
1:  c62cbd6ac = 1:  c62cbd6ac Fix org-in-archived-heading-p

 lisp/org.el              | 5 ++---
 testing/lisp/test-org.el | 7 ++++++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index d4fb18465..e44cdf1ca 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19285,10 +19285,9 @@ This function also checks ancestors of the current headline,
 unless optional argument NO-INHERITANCE is non-nil."
   (cond
    ((org-before-first-heading-p) nil)
-   ((let ((tags (nth 5 (org-heading-components))))
+   ((let ((tags (org-get-tags nil 'local)))
       (and tags
-	   (let ((case-fold-search nil))
-	     (string-match-p org-archive-tag tags)))))
+	   (cl-some (apply-partially #'string= org-archive-tag) tags))))
    (no-inheritance nil)
    (t
     (save-excursion (and (org-up-heading-safe) (org-in-archived-heading-p))))))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 5172afeec..a18d42a98 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2103,7 +2103,12 @@
   (should-not
    (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
      (goto-char (point-max))
-     (org-in-archived-heading-p t))))
+     (org-in-archived-heading-p t)))
+   ;; Archive tag containing ARCHIVE as substring
+   (should-not
+    (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
+     (goto-char (point-max))
+     (org-in-archived-heading-p))))
 
 (ert-deftest test-org/entry-blocked-p ()
   ;; Check other dependencies.
-- 
2.26.2


Reply via email to