Skip to content

Instantly share code, notes, and snippets.

@marcowahl
Last active December 20, 2019 06:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save marcowahl/c12ed4b2df9748ad7185338394b92445 to your computer and use it in GitHub Desktop.
Save marcowahl/c12ed4b2df9748ad7185338394b92445 to your computer and use it in GitHub Desktop.
org-save-org-structure-as-dir-file-skeleton to save the org structure as dirs and files (marked with tag :file:)
(defun org-interpret-org-as-dir-file-skeleton ()
"Return the outline paths as lists.
Separated in those headlines not tagged 'file' and those tagged with 'file'."
(let (output-files output-dirs)
(org-map-entries
(lambda ()
(let* ((headline (car (cddddr (org-heading-components))))
(headline-path
(reverse
(cons
headline (reverse (org-get-outline-path))))))
(cond
((member "file" (org-get-local-tags))
(setf output-files (cons headline-path output-files)))
(t
(setf output-dirs (cons headline-path output-dirs)))))))
(list output-dirs output-files)))
(defun org-save-org-structure-as-dir-file-skeleton ()
"Write a directory/file structure to disk according to the Org structure.
Every headline gets interpreted as directory except when it's
tagged with 'file'.
This function expects an org structure which can logically be
mapped to a filesystem. E.g. no dirs within files may occur."
(interactive)
(let ((dirs-and-files (org-interpret-org-as-dir-file-skeleton)))
(mapc
#'make-directory
(mapcar
(lambda (x) (reduce (lambda (x y) (concat x "/" y)) x))
(sort (car dirs-and-files) (lambda (x y) (< (length x) (length y))))))
(mapc
(lambda (x) (save-excursion
(save-buffer (set-buffer (find-file-noselect x t)))))
(mapcar
(lambda (x) (reduce (lambda (x y) (concat x "/" y)) x))
(cadr dirs-and-files)))))
@novoid
Copy link

novoid commented Nov 18, 2016

This features reminds me of a research tool called Planz: http://kftf.ischool.washington.edu/planner_index.htm
If you want further information on Planz or similar research prototypes, drop me a line ;-)

@marcowahl
Copy link
Author

Thanks for the hint and the offer! Planz looks interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment