I'm working with an org-mode file that might contain headlines and text, like
* Headline 1
:PROPERTIES:
:ID: h1
:END:
This is some text.
** Subheading A
:PROPERTIES:
:ID: s1
:END:
The subheading can also have text.
Suppose I have a string bound to the symbol mytext
that looks like
:PROPERTIES:
:ID: h1
:END:
This is some UPDATED text.
As you can see, it can
be multlined.
I want to replace h1's "body" text with the stuff in mytext
(including the Properties drawer and all), but leave any subtrees alone. So the end result should look like
* Headline 1
:PROPERTIES:
:ID: h1
:END:
This is some UPDATED text.
As you can see, it can
be multlined.
** Subheading A
:PROPERTIES:
:ID: s1
:END:
The subheading can also have text.
What's the fastest / easiest way to do this with elisp?
delete-region
andinsert
your symbol/text. There are insufficient details in the question be more specific as we do not know how it is that the region to be replaced will be selected/chosen, where the cursor is in the buffer, whether the region is presently selected/highlighted, whether the original poster is looking for a select region consisting of the subtree in relation to wherever the cursor is presently located, etc.org-cut-subtree
: "Cut the current subtree into the clipboard. With prefix arg N, cut this many sequential subtrees. This is a short-hand for marking the subtree and then cutting it."