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

2022-01-15 Thread Ihor Radchenko
Ihor Radchenko  writes:

> Johan Tolö  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.

For record, this patch has been incorporated as parts of two other
patches.

Best,
Ihor



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

2021-10-03 Thread Ihor Radchenko
Johan Tolö  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.yanta...@gmail.com>
From: Ihor Radchenko 
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@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  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  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



Re: org-attach-use-inheritance inherits from sibling

2021-10-03 Thread Johan Tolö



Ihor Radchenko  writes:
I cannot reproduce on current main. Are you still seeing this 
problem?


Yes I believe I am. Also, it does not seem to be an org-attach 
issue but rather an issue with how org gets properties with 
inheritance.


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.


This example illustrates the problem:

 beginning of buffer 
* Top heading
:PROPERTIES:
:ID:   acf18561-7a84-4703-96c6-1aceccd46b33
:END:

* Second heading
 
#+begin_src emacs-lisp

 (load "org.el")
 (load "org-id.el")
 (org-entry-get nil "id" t)
#+end_src

#+RESULTS:
: acf18561-7a84-4703-96c6-1aceccd46b33

 end of buffer 


--
Johan Tolö



Re: org-attach-use-inheritance inherits from sibling

2021-10-01 Thread Ihor Radchenko
Johan Tolö  writes:

> Hi,
> I have set 'org-attach-use-inheritance' to t. If a heading has no 
> parents it seems to inherit from the first heading in the file 
> which has either the ID or DIR property set, ie from the first 
> sibling above it. I'm guessing this is not the expected behaviour?

I cannot reproduce on current main. Are you still seeing this problem?

Best,
Ihor



org-attach-use-inheritance inherits from sibling

2021-09-06 Thread Johan Tolö

Hi,
I have set 'org-attach-use-inheritance' to t. If a heading has no 
parents it seems to inherit from the first heading in the file 
which has either the ID or DIR property set, ie from the first 
sibling above it. I'm guessing this is not the expected behaviour?


Johan


--
Johan