From 510bc7b5b4d99ff548de81f27a1a6595de99a480 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 11 Feb 2021 15:05:34 -0500 Subject: [PATCH] Revert "Don't auto-create directory when opening files" This reverts commit 4d7640b4c2d96374631e31f7917ae53eeec2239c. --- core/core-editor.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/core-editor.el b/core/core-editor.el index 724a32802..85945973c 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -72,6 +72,19 @@ possible." ;; warning as it will redirect you to the existing buffer anyway. (setq find-file-suppress-same-file-warnings t) +;; Create missing directories when we open a file that doesn't exist under a +;; directory tree that may not exist. +(add-hook! 'find-file-not-found-functions + (defun doom-create-missing-directories-h () + "Automatically create missing directories when creating new files." + (unless (file-remote-p buffer-file-name) + (let ((parent-directory (file-name-directory buffer-file-name))) + (and (not (file-directory-p parent-directory)) + (y-or-n-p (format "Directory `%s' does not exist! Create it?" + parent-directory)) + (progn (make-directory parent-directory 'parents) + t)))))) + ;; Don't generate backups or lockfiles. While auto-save maintains a copy so long ;; as a buffer is unsaved, backups create copies once, when the file is first ;; written, and never again until it is killed and reopened. This is better