From f53d1e2005a26a52427b7514f2d3e7cfa3ff2562 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 2 Dec 2017 12:21:03 +0100 Subject: [PATCH] Let `or-export-last-sibling-p' handle discontinuous headlines * lisp/ox.el (org-export-last-sibling-p): Handle discontinuous headlines. * testing/lisp/test-ox.el (test-org-export/last-sibling-p): Add test. Fixes: 24836 --- lisp/ox.el | 12 ++++++++---- testing/lisp/test-ox.el | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index 3c052a29f..8ea47d8ba 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4053,11 +4053,15 @@ used as a communication channel." (memq (org-element-type (org-export-get-previous-element blob info)) '(nil section))) -(defun org-export-last-sibling-p (blob info) - "Non-nil when BLOB is the last sibling in its parent. -BLOB is an element or an object. INFO is a plist used as +(defun org-export-last-sibling-p (datum info) + "Non-nil when DATUM is the last sibling in its parent. +DATUM is an element or an object. INFO is a plist used as a communication channel." - (not (org-export-get-next-element blob info))) + (let ((next (org-export-get-next-element datum info))) + (or (not next) + (and (eq 'headline (org-element-type datum)) + (> (org-element-property :level datum) + (org-element-property :level next)))))) ;;;; For Keywords diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 79429371f..8b2ef8105 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -2677,7 +2677,13 @@ Para2" (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:" (org-element-map tree 'headline (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no)) - info)))))) + info))))) + ;; Handle gracefully discontinuous headings. + (should + (equal '(yes yes) + (org-test-with-parsed-data "** S\n* H" + (org-element-map tree 'headline + (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))))))) (ert-deftest test-org-export/handle-inlinetasks () "Test inlinetask export."