Commits

Fuco  committed 1705562

Added pre-save hook to create directory if it doesn't exist

  • Participants
  • Parent commits f1a70c7

Comments (0)

Files changed (2)

File files/defuns-buffer.el

   (cleanup-buffer-safe)
   (indent-buffer))
 
+(defun my-create-directory-on-save ()
+  (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)))))
+
 ;; Borrowed from https://gist.github.com/1415844
 ;; Also see http://emacsworld.blogspot.com/2011/12/moving-buffers-between-windows.html
 (require 'cl)

File files/global.el

 
 ;; Trailing whitespace is unnecessary
 (add-hook 'before-save-hook 'cleanup-buffer-safe)
+(add-hook 'before-save-hook 'my-create-directory-on-save)
 
 ;; Trash can support
 (setq delete-by-moving-to-trash t)