Skip to content

Instantly share code, notes, and snippets.

@jwinder
Created May 21, 2013 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwinder/5620306 to your computer and use it in GitHub Desktop.
Save jwinder/5620306 to your computer and use it in GitHub Desktop.
;; Create non-existent directories containing a new file before saving
(add-hook 'before-save-hook
(lambda ()
(when buffer-file-name
(let ((dir (file-name-directory buffer-file-name)))
(when (and (not (file-exists-p dir))
(y-or-n-p (format "Directory %s does not exist. Create it?" dir)))
(make-directory dir t))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment