I need from time to time to convert an Org Heading to a file-note. With v1 of Org-roam I used to do it using a custom function that eventually calls (org-roam-capture--capture).
That function was removed from v2 and the org-roam capture mechanism has been changed.
Can someone share a snippet or give me some pointers how to rewrite my old function and make it compatible with v2?
A very simple way would be to create a function to work on the current subtree to do something like this:
Narrow to subtree org-narrow-to-subtree
Create a new buffer
Insert the entire subtree to the new buffer
Save the buffer with .org extension
Not sure if there is anything more you would like to do, but you could also add the following rather easily:
Use the current subtree’s heading (title) as the new file’s title
e.g. At point 1 of the narrowed buffer, org-element-at-point and org-element-property to get the headline’s title and insert it to as #+title: <insert the text here> – Simply use format or concat
Generate a new Org-ID for the file
Simply use org-id-get-create
That makes sense. However, this won’t protect from accidentally creating a note file with the same title multiple times. Besides, using org-roam-capture’s machinery would allow creating new file-notes exactly as stated in the template.
And also opens the possibility for implementing the reverse - re-filing the entire content of a file-note as a subheading to another node (with subsequent deletion of the file). For example, no need to keep whole file titled “Taxonomy”, if it can easily be just a heading in a file-note for “Biology”.
Finally, I had some time to dig around the issue and wrote this:
Currently, it only knows how to convert a Heading to a separate file-note. At some point I’d like to extend this, so it works the other way around too. And I also would like to be able to “re-file” content, moving it from one node to another.