Emacs: Offer to create missing directories
Alan Pearce alan@alanpearce.co.uk
Wed, 17 Dec 2014 20:09:20 +0000
1 files changed, 7 insertions(+), 0 deletions(-)
jump to
M tag-emacs/emacs.d/init.el → tag-emacs/emacs.d/init.el
@@ -406,6 +406,13 @@ (delete-file filename) (kill-this-buffer) (message "File '%s' successfully removed" filename))))) +(defun my-create-non-existent-directory () + (let ((parent-directory (file-name-directory buffer-file-name))) + (when (and (not (file-exists-p parent-directory)) + (y-or-n-p (format "Directory `%s' does not exist! Create it?" parent-directory))) + (make-directory parent-directory t)))) +(add-to-list 'find-file-not-found-functions #'my-create-non-existent-directory) + (defun kill-or-delete-this-buffer-dwim (&optional arg) "Kills current buffer. With prefix arg, delete it." (interactive "P")