diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 78cdf6602..4c6c8c866 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -108,6 +108,8 @@ increased. See manual for details. Inline source code was used to be removed upon exporting. They are now handled as standard code blocks, i.e., the source code can appear in the output, depending on the parameters. +*** Extend ~org-export-first-sibling-p~ and ~org-export-last-sibling-p~ +These functions now support any element or object, not only headlines. ** Miscellaneous *** File names in links accept are now compatible with URI syntax Absolute file names can now start with =///= in addition to =/=. E.g., diff --git a/lisp/ox.el b/lisp/ox.el index f81b76945..72aafa27e 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3887,16 +3887,19 @@ title is defined, fall-back to the regular title." (or (org-element-property :alt-title headline) (org-element-property :title headline))) -(defun org-export-first-sibling-p (headline info) - "Non-nil when HEADLINE is the first sibling in its sub-tree. -INFO is a plist used as a communication channel." - (not (eq (org-element-type (org-export-get-previous-element headline info)) - 'headline))) +(defun org-export-first-sibling-p (blob info) + "Non-nil when BLOB is the first sibling in its parent. +BLOB is an element or an object. If BLOB is a headline, non-nil +means it is the first sibling in the sub-tree. INFO is a plist +used as a communication channel." + (memq (org-element-type (org-export-get-previous-element blob info)) + '(nil section))) -(defun org-export-last-sibling-p (headline info) - "Non-nil when HEADLINE is the last sibling in its sub-tree. -INFO is a plist used as a communication channel." - (not (org-export-get-next-element headline info))) +(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 +a communication channel." + (not (org-export-get-next-element blob info))) ;;;; For Keywords diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el index 9bde04ef7..e9029581a 100644 --- a/testing/lisp/test-ox.el +++ b/testing/lisp/test-ox.el @@ -1719,10 +1719,23 @@ Paragraph[fn:1]" (should (equal '(yes yes no) - (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3" + (org-test-with-parsed-data "* H\n** H 2\n** H 3" (org-element-map tree 'headline (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no)) info)))) + (should + (equal '(yes no) + (org-test-with-parsed-data "- item\n\n para" + (org-element-map tree 'paragraph + (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no)) + info)))) + ;; Ignore sections for headlines. + (should + (equal '(yes yes) + (org-test-with-parsed-data "* H\nSection\n** H 2" + (org-element-map tree 'headline + (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no)) + info)))) ;; Ignore headlines not exported. (should (equal @@ -1743,6 +1756,12 @@ Paragraph[fn:1]" (org-element-map tree 'headline (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no)) info)))) + (should + (equal '(no yes) + (org-test-with-parsed-data "- item\n\n para" + (org-element-map tree 'paragraph + (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no)) + info)))) ;; Ignore headlines not exported. (should (equal