publicvoit · 2022-05-25 09:57
Hi,
I need to maintain an Orgdown file in a repository. For various reasons, I don't want to edit that file directly. I want to keep the data as a sub-heading in one of my agenda files as the "main" data source.
Therefore, I'm wondering if anybody has a workflow where a certain sub-hierarchy (defined by an ID property) is automatically copied to a defined file somewhere else. This external file only contains the single sub-hierarchy and no additional content. There is no-one editing that file besides me so a "blind" one-directional export (overwriting the previous version) + commit is viable.
Is there anybody who did this already?
diamondnbond · 2022-05-25 10:04
Look into `org-refile` and setup `org-refile-targets` to point to the destination file then run `C-c C-w` on a heading in your "main" data source to refile it to a selected target file from the `org-refile-targets` list.
Note: this won't overwrite but instead will simply append to the target file.
yantar92 · 2022-05-25 10:29
> There is no-one editing that file besides me so a "blind" one-directional export (overwriting the previous version) + commit is viable.
Just use Org subtree export to org (C-e C-s O o). You can insert the commit number using macro. As usual, you can do it programatically in after-save-hook by calling `org-export-as` directly. Or you can setup publishing.
publicvoit · 2022-05-25 15:33
For reference, I found this piece of John Kitchin others might be interested in: https://kitchingroup.cheme.cmu.edu/blog/2013/12/08/Selectively-exporting-headlines-in-org-mode/
publicvoit · 2022-05-25 15:57
Thanks u/yantar92
OMG: I never realized that Org is able to export to Org as well. :-)
Well, in this case, this my preferred (manual export) way to go for now:
#+BEGIN_SRC emacs-lisp :exports none
;; Sync this sub-hierarchy to git repo and invoke git status:
(let (
(outputfilename (org-org-export-to-org nil t nil nil))
(destinationfilename "/home/path/to/result/repo/myfile.org")
)
(rename-file outputfilename destinationfilename t)
(message (concat "Content exported to: " destinationfilename))
(find-file destinationfilename)
(magit-status)
)
#+END_SRC
*Ceterum autem censeo* [*don't contribute anything relevant in web forums like Reddit only*](https://karl-voit.at/2020/10/23/avoid-web-forums)