How to open external sourcecode files inside org-mode codeblocks, in a way that files can be viewed and saved while saving the org-mode document.
Kinda of a 'Nested Buffers' feature?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityHow to open external sourcecode files inside org-mode codeblocks, in a way that files can be viewed and saved while saving the org-mode document.
Kinda of a 'Nested Buffers' feature?
I can think of a few variations and options one might want to add, but this seems to work for me. Try it, @zotherstupidguy, and get back to me with suggestions.
Upon saving the org file it will look for any heading containing a property of SAVE-TO-FILE
whose value is the filename to save to, i.e.:
:PROPERTIES:
:SAVE-TO-FILE: ~/my-ext-file
:END:
It will save everything in that heading, including the heading itself and the property drawer.
(defun save-headings-external ()
"Save all heading containing special property to an external file"
(interactive)
(when (string= major-mode "org-mode")
(goto-char (point-min))
(let (-extfname -start)
(while (re-search-forward ":PROPERTIES:" nil t)
(when (setq -extfname (org-entry-get (point) "SAVE-TO-FILE"))
(save-excursion
(org-back-to-heading)
(setq -start (point))
(org-forward-heading-same-level 1 t)
(write-region -start (point) -extfname)
(message "Wrote '%s'" -extfname)))))))
(add-hook 'write-file-hooks 'save-headings-external)
(You can delete the (message...)
if you want)