emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: "Johan Tolö" <johan@toloe.se>
Cc: emacs-orgmode@gnu.org
Subject: [PATCH] org-attach-use-inheritance inherits from sibling
Date: Sun, 03 Oct 2021 22:40:50 +0800	[thread overview]
Message-ID: <87o886cgst.fsf@localhost> (raw)
In-Reply-To: <87zgrqqlcs.fsf@toloe.se>

[-- Attachment #1: Type: text/plain, Size: 674 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Do-not-unconditionally-inherit-from-headline-.patch --]
[-- Type: text/x-diff, Size: 3356 bytes --]

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 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	other threads:[~2021-10-03 14:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06  9:22 org-attach-use-inheritance inherits from sibling Johan Tolö
2021-10-01 14:19 ` Ihor Radchenko
2021-10-03 13:28   ` Johan Tolö
2021-10-03 14:40     ` Ihor Radchenko [this message]
2022-01-15 11:52       ` [PATCH] " Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o886cgst.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=johan@toloe.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).