0

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.

3
  • Can you please edit your question and specify how the Org mode file itself looks to begin with and how it should look afterwards (and also what to do with the excised piece)?
    – NickD
    Commented Nov 1, 2022 at 13:04
  • Thank you for updating the question! One thing to note is that in the example, the structure of the tree has now changed: there is no longer a level 2 headline, so the level 3 headlines are inherited by whatever level 1 headline the subtree was hanging off. Is that intentional?
    – NickD
    Commented Nov 1, 2022 at 15:10
  • This looks like an X-Y problem to me: you are trying to do something which (at least at first sight) does not make sense. Why are you trying to do that?
    – NickD
    Commented Nov 1, 2022 at 20:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.