emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Possible bug in `org-subtree--get-subtree-options`?
@ 2022-03-14 17:42 Kaushal Modi
  2022-10-18  4:12 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Kaushal Modi @ 2022-03-14 17:42 UTC (permalink / raw)
  To: emacs-org list, Nicolas Goaziou

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

Hello Nicolas,

Today I was debugging something where a subtree export wasn't recognizing
the EXPORT_OPTIONS property set in that subtree.

MWE:

=====
* Top level
** Allow broken links, but mark them
:PROPERTIES:
:EXPORT_FILE_NAME: allow-broken-links-but-mark-them
:EXPORT_OPTIONS: broken-links:mark
:END:
=====

1. Move cursor to BOL of "** Allow broken links, but mark them" line.
2. M-: (org-export--get-subtree-options)

Output:

(:title (#("Top level" 0 9 (:parent #1))))

Issue: Point is already on a heading, but it is jumping to the parent
heading and returning that heading's properties.

Debugging through how the export options got parsed in subtree exports, I
reached the `org-export--get-subtree-options' function and this line in
there:

;;
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ox.el#n1425
(if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t))

It looks like the if condition actions are swapped here.

Should it be:

(if (org-at-heading-p) (org-back-to-heading t) (org-up-heading-safe))
;; If point is in a heading, just go to the BOL  (org-back-to-heading t)
;; Otherwise, jump up to a parent-heading if available.

If I evaluate that function after updating that if condition as above and
redo the steps I mentioned above, the output is now what I expect:

(:with-broken-links mark :title (#("Allow broken links, but mark them" 0 33
(:parent #1))))

I am only surprised that this line has been there at least since 2015.

Thanks!

--
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 2281 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Possible bug in `org-subtree--get-subtree-options`?
  2022-03-14 17:42 Possible bug in `org-subtree--get-subtree-options`? Kaushal Modi
@ 2022-10-18  4:12 ` Ihor Radchenko
  2022-11-27  8:51   ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2022-10-18  4:12 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: emacs-org list, Nicolas Goaziou

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

Kaushal Modi <kaushal.modi@gmail.com> writes:

> Today I was debugging something where a subtree export wasn't recognizing
> the EXPORT_OPTIONS property set in that subtree.
>
> MWE:
>
> =====
> * Top level
> ** Allow broken links, but mark them
> :PROPERTIES:
> :EXPORT_FILE_NAME: allow-broken-links-but-mark-them
> :EXPORT_OPTIONS: broken-links:mark
> :END:
> =====
>
> 1. Move cursor to BOL of "** Allow broken links, but mark them" line.
> 2. M-: (org-export--get-subtree-options)
>
> Output:
>
> (:title (#("Top level" 0 9 (:parent #1))))
>
> Issue: Point is already on a heading, but it is jumping to the parent
> heading and returning that heading's properties.
>
> Debugging through how the export options got parsed in subtree exports, I
> reached the `org-export--get-subtree-options' function and this line in
> there:
>
> ;;
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ox.el#n1425
> (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t))
>
> It looks like the if condition actions are swapped here.

Not really swapped. A simple (org-back-to-heading t) will probably be
enough. See the attached patch.

However, I am concerned that one of the tests is actually assuming that
current subtree in the below example includes "Heading".

* Heading
** Child
** Child<point>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-export-get-subtree-options-Do-not-jump-to-parent.patch --]
[-- Type: text/x-patch, Size: 1941 bytes --]

From e2c1dc3955eb54cee7ce137d548c687e378f4c8a Mon Sep 17 00:00:00 2001
Message-Id: <e2c1dc3955eb54cee7ce137d548c687e378f4c8a.1666066170.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Tue, 18 Oct 2022 12:07:37 +0800
Subject: [PATCH] org-export--get-subtree-options: Do not jump to parent
 subtree

* lisp/ox.el: Never jump to parent heading even when point is at an
existing heading.
* testing/lisp/test-ox.el (test-org-export/get-subtree-options): Fix
test assuming that current subtree may include parent.

Reported-by: Kaushal Modi <kaushal.modi@gmail.com>
Link: https://orgmode.org/list/CAFyQvY3mxi4DRTS+W-AX7bFELVujqH4DODEYPy3hyGRRuMEPSw@mail.gmail.com
---
 lisp/ox.el              | 2 +-
 testing/lisp/test-ox.el | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 92f6010a0..9f44ec3ef 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1434,7 +1434,7 @@ (defun org-export--get-subtree-options (&optional backend)
   ;; property is the keyword with "EXPORT_" appended to it.
   (org-with-wide-buffer
    ;; Make sure point is at a heading.
-   (if (org-at-heading-p) (org-up-heading-safe) (org-back-to-heading t))
+   (org-back-to-heading t)
    (let ((plist
 	  ;; EXPORT_OPTIONS are parsed in a non-standard way.  Take
 	  ;; care of them right from the start.
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 42867919b..0d39160b6 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -388,7 +388,7 @@ (ert-deftest test-org-export/get-subtree-options ()
 	    (plist-get (org-export-get-environment nil t) :date))))
   ;; Still grab correct options when section above is empty.
   (should
-   (equal '("H1")
+   (equal '("H12")
 	  (org-test-with-temp-text "* H1\n** H11\n** H12<point>"
 	    (plist-get (org-export-get-environment nil t) :title))))
   ;; More than one property can refer to the same node property.
-- 
2.35.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Possible bug in `org-subtree--get-subtree-options`?
  2022-10-18  4:12 ` Ihor Radchenko
@ 2022-11-27  8:51   ` Ihor Radchenko
  0 siblings, 0 replies; 3+ messages in thread
From: Ihor Radchenko @ 2022-11-27  8:51 UTC (permalink / raw)
  To: Kaushal Modi; +Cc: emacs-org list, Nicolas Goaziou

Ihor Radchenko <yantar92@posteo.net> writes:

> Not really swapped. A simple (org-back-to-heading t) will probably be
> enough. See the attached patch.
>
> However, I am concerned that one of the tests is actually assuming that
> current subtree in the below example includes "Heading".

No concerns have been raised.
Applied onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=927621910
Fixed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-27  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 17:42 Possible bug in `org-subtree--get-subtree-options`? Kaushal Modi
2022-10-18  4:12 ` Ihor Radchenko
2022-11-27  8:51   ` Ihor Radchenko

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).