emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] org-attach-use-inheritance inherits from sibling


From: Ihor Radchenko
Subject: [PATCH] org-attach-use-inheritance inherits from sibling
Date: Sun, 03 Oct 2021 22:40:50 +0800

Johan Tolö <johan@toloe.se> writes:

> If "* Top heading" is the first heading in the buffer with nothing 
> above it, not even a whitespace/newline, then '(org-entry-get nil 
> "id" t)' with point in "* Second heading" will return the id of 
> "Top heading". If there is anything before "Top heading" then 
> 'nil' will be returned.
>
> This happens when I run 'emacs -Q' from within the "lisp" 
> directory of a newly cloned "org-mode" main branch.

Ouch. Thanks for reporting!

Confirmed

The fix is attached.

Dear all,

I had to fix one of the tests, that apparently was only working because
the bug existed. Please double check.

Best,
Ihor

>From 199e64cf8264025cc78f79c3bdb278920685281f Mon Sep 17 00:00:00 2001
Message-Id: 
<199e64cf8264025cc78f79c3bdb278920685281f.1633271912.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sun, 3 Oct 2021 22:10:31 +0800
Subject: [PATCH] org.el: Do not unconditionally inherit from headline right at
 BOB

* lisp/org.el (org-entry-get-with-inheritance): Consider scenario when
there is a headline starting at BOB and we are getting an inherited
property at non-child headline below.  Previous implementation would
erroneously inherit the property value from the first headline in
buffer.

* testing/lisp/test-org.el (test-org/entry-get): Add test and fix an
existing test that worked because this bug existed.

Fixes 
87zgrqqlcs.fsf@toloe.se/T/#mfcab9bd710d837a0cd9d4cf331655ee39b8ad3ca">https://list.orgmode.org/87zgrqqlcs.fsf@toloe.se/T/#mfcab9bd710d837a0cd9d4cf331655ee39b8ad3ca
---
 lisp/org.el              | 14 ++++++++++++--
 testing/lisp/test-org.el |  6 +++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index bc0ea24be..bcb38f07f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -13163,7 +13163,7 @@ (defun org-entry-get-with-inheritance (property 
&optional literal-nil)
 However, if LITERAL-NIL is set, return the string value \"nil\" instead."
   (move-marker org-entry-property-inherited-from nil)
   (org-with-wide-buffer
-   (let (value)
+   (let (value at-bob-no-heading)
      (catch 'exit
        (while t
         (let ((v (org--property-local-values property literal-nil)))
@@ -13177,7 +13177,17 @@ (defun org-entry-get-with-inheritance (property 
&optional literal-nil)
             (org-back-to-heading-or-point-min t)
             (move-marker org-entry-property-inherited-from (point))
             (throw 'exit nil))
-           ((org-up-heading-or-point-min))
+            ((or (org-up-heading-safe)
+                 (and (not (bobp))
+                      (goto-char (point-min))
+                      nil)
+                 ;; `org-up-heading-safe' returned nil.  We are at low
+                 ;; level heading or bob.  If there is headline
+                 ;; there, do not try to fetch its properties.
+                 (and (bobp)
+                      (not at-bob-no-heading)
+                      (not (org-at-heading-p))
+                      (setq at-bob-no-heading t))))
            (t
             (let ((global (org--property-global-or-keyword-value property 
literal-nil)))
               (cond ((not global))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 18d41a0d2..7b1ce8cd0 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -5831,6 +5831,10 @@ (ert-deftest test-org/entry-get ()
    (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
      (let ((org-use-property-inheritance nil))
        (org-entry-get (point-max) "A" 'selective))))
+  (should-not
+   (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
+     (let ((org-use-property-inheritance t))
+       (org-entry-get (point-max) "A" t))))
   (should
    (equal
     "1 2"
@@ -5853,7 +5857,7 @@ (ert-deftest test-org/entry-get ()
    (equal
     "1 2"
     (org-test-with-temp-text
-       "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 
2\n:END:"
+       "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 
2\n:END:"
       (org-entry-get (point-max) "A" t))))
   (should
    (equal "1"
-- 
2.32.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]