I have a org-element AST of a subtree which I want to make into a separate file. It looks necessarily like
(org-data nil
(headline (...metadata...) ; (a)
(section (...metadata...) ; (b)
...stuff in section
(headline (...metadata...) ; (c)
... and so on))) ; (...)
It corresponds to the subtree
** header (a)
:PROPERTIES:
diverse properties
:END:
Stuffs in section (b)
*** Subheader (c)
foo
*** Other subheader (...)
All I need is to remove the first headline of the AST. And get
(org-data nil
(section (...metadata...) ; (b)
...stuff in section
(headline (...metadata...) ; (c)
... and so on)) ; (...)
Which would correspond to
Stuffs in section (b)
*** Subheader (c)
foo
*** Other subheader (...)
This ugly hack has worked, but sometimes fails :
(org-element-interpret-data
(cons 'org-data (cons 'nil
(org-element-contents
(car (org-element-contents tree))))))
- It is ugly since the ast explodes in size because each :parent which was a mere link to the headline is now a full copy of the ast.
- Moreover it does not remove the headline properties drawer which is considered part of the following section (which does not really makes sense).
- And sometimes it fails miserably.
I'd really like to have an "org-elemental" way to this problem rather than resorting to edition in a buffer because the rest of my program uses only org-element.