Assembling Org Mode Files with Transclusion

News

Discovering Uses for Transclusion

Today we’ll be taking a look at the org-transclusion package to see how we might be able to use it to assemble Org files by including other text files, either the entire file or subsections of it depending on file type.

https://github.com/nobiot/org-transclusion

Transclusion is better than the built-in #+INCLUDE syntax because it supports more types of files and the included content gets dynamically updated!

Here’s what we’ll try:

  • Creating larger Org Mode documents like articles or books from Denote notes
  • Literate programming and configuration from original source files
  • Publishing/exporting transcluded Org documents
  • … and more!

Adding Denote Link Support

Kudos to Jabbo (Stefan Thesing) for putting this together, as found on this GitHub issue:

https://github.com/nobiot/org-transclusion/issues/160#issuecomment-1377714791

(defun denote-org-transclusion-add (link plist)
  (when (string= "denote" (org-element-property :type link))
    (let* ((denote-full (org-element-property :path link))     ;; get denote id from denote:<denote-full> link
            (denote-parts (string-split denote-full "::"))
            (file-path (denote-get-path-by-id (car denote-parts)))     ;; path resolved by the id
            (new-link (with-temp-buffer                       ;; create a [[file:/path/to/denote/note]] org link
                        (insert "file:")                      ;; and store it in 'new-link' variable
                        (insert file-path)
                        (when (cadr denote-parts)
                          (insert "::" (cadr denote-parts)))
                        (beginning-of-buffer)
                        (org-element-link-parser))))
      (org-transclusion-add-org-file new-link plist))))

(cl-pushnew 'denote-org-transclusion-add org-transclusion-add-functions)

Discuss on the forum!

You can discuss this stream on the forum on this thread (thanks, Ashraz!):

https://forum.systemcrafters.net/t/assembling-org-mode-files-with-transclusion-system-crafters-live/1570

Subscribe to the System Crafters Newsletter!
Stay up to date with the latest System Crafters news and updates! Read the Newsletter page for more information.
Name (optional)
Email Address