From: Glenn Morris Date: Tue, 12 Feb 2013 08:36:09 +0000 (-0800) Subject: * files.el (basic-save-buffer): Offer to create a non-existing directory. X-Git-Tag: emacs-24.3.90~173^2~7^2~77 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0b244335656c7f425b139cc8bad7f26cb749d0e1;p=emacs.git * files.el (basic-save-buffer): Offer to create a non-existing directory. Fixes: debbugs:3016 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d5fe7c4047d..0aaead88b9c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2013-02-12 Glenn Morris + * files.el (basic-save-buffer): + Offer to create a non-existing directory. (Bug#3016) + * calc/calc-graph.el (calc-graph-show-dumb): * calendar/calendar.el (calendar-mode-map): * cus-edit.el (custom-mode-map): diff --git a/lisp/files.el b/lisp/files.el index 890834d4af0..f9ed65b8ac0 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4563,28 +4563,39 @@ Before and after saving the buffer, this function runs (not (file-exists-p buffer-file-name)))) (let ((recent-save (recent-auto-save-p)) setmodes) - ;; If buffer has no file name, ask user for one. - (or buffer-file-name - (let ((filename - (expand-file-name - (read-file-name "File to save in: " - nil (expand-file-name (buffer-name)))))) - (if (file-exists-p filename) - (if (file-directory-p filename) - ;; Signal an error if the user specified the name of an - ;; existing directory. - (error "%s is a directory" filename) - (unless (y-or-n-p (format "File `%s' exists; overwrite? " - filename)) - (error "Canceled"))) - ;; Signal an error if the specified name refers to a - ;; non-existing directory. - (let ((dir (file-name-directory filename))) - (unless (file-directory-p dir) - (if (file-exists-p dir) - (error "%s is not a directory" dir) - (error "%s: no such directory" dir))))) - (set-visited-file-name filename))) + (if buffer-file-name + (let ((dir (file-name-directory + (expand-file-name buffer-file-name)))) + (unless (file-exists-p dir) + (if (y-or-n-p + (format "Directory `%s' does not exist; create? " dir)) + (make-directory dir t) + (error "Canceled")))) + ;; If buffer has no file name, ask user for one. + (let ((filename + (expand-file-name + (read-file-name "File to save in: " + nil (expand-file-name (buffer-name)))))) + (if (file-exists-p filename) + (if (file-directory-p filename) + ;; Signal an error if the user specified the name of an + ;; existing directory. + (error "%s is a directory" filename) + (unless (y-or-n-p (format "File `%s' exists; overwrite? " + filename)) + (error "Canceled"))) + ;; Signal an error if the specified name refers to a + ;; non-existing directory. + (let ((dir (file-name-directory filename))) + (unless (file-directory-p dir) + (if (file-exists-p dir) + (error "%s is not a directory" dir) + (if (y-or-n-p + (format "Directory `%s' does not exist; create? " + dir)) + (make-directory dir t) + (error "Canceled")))))) + (set-visited-file-name filename))) (or (verify-visited-file-modtime (current-buffer)) (not (file-exists-p buffer-file-name)) (yes-or-no-p