* org-attach-use-inheritance inherits from sibling @ 2021-09-06 9:22 Johan Tolö 2021-10-01 14:19 ` Ihor Radchenko 0 siblings, 1 reply; 5+ messages in thread From: Johan Tolö @ 2021-09-06 9:22 UTC (permalink / raw) To: emacs-orgmode 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: org-attach-use-inheritance inherits from sibling 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ö 0 siblings, 1 reply; 5+ messages in thread From: Ihor Radchenko @ 2021-10-01 14:19 UTC (permalink / raw) To: Johan Tolö; +Cc: emacs-orgmode Johan Tolö <johan@toloe.se> 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: org-attach-use-inheritance inherits from sibling 2021-10-01 14:19 ` Ihor Radchenko @ 2021-10-03 13:28 ` Johan Tolö 2021-10-03 14:40 ` [PATCH] " Ihor Radchenko 0 siblings, 1 reply; 5+ messages in thread From: Johan Tolö @ 2021-10-03 13:28 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode Ihor Radchenko <yantar92@gmail.com> 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ö ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] org-attach-use-inheritance inherits from sibling 2021-10-03 13:28 ` Johan Tolö @ 2021-10-03 14:40 ` Ihor Radchenko 2022-01-15 11:52 ` Ihor Radchenko 0 siblings, 1 reply; 5+ messages in thread From: Ihor Radchenko @ 2021-10-03 14:40 UTC (permalink / raw) To: Johan Tolö; +Cc: emacs-orgmode [-- 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] org-attach-use-inheritance inherits from sibling 2021-10-03 14:40 ` [PATCH] " Ihor Radchenko @ 2022-01-15 11:52 ` Ihor Radchenko 0 siblings, 0 replies; 5+ messages in thread From: Ihor Radchenko @ 2022-01-15 11:52 UTC (permalink / raw) To: Johan Tolö; +Cc: emacs-orgmode Ihor Radchenko <yantar92@gmail.com> writes: > 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. For record, this patch has been incorporated as parts of two other patches. Best, Ihor ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-15 11:50 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH] " Ihor Radchenko 2022-01-15 11:52 ` Ihor Radchenko
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.