From: Glenn Morris Date: Thu, 21 Feb 2013 02:44:06 +0000 (-0500) Subject: * lisp/files.el (basic-save-buffer): Move check for existing parent directory X-Git-Url: http://git.hcoop.net/bpt/emacs.git/commitdiff_plain/b367ec7bc10f625cb9769bfca0b8f502cd475e22 * lisp/files.el (basic-save-buffer): Move check for existing parent directory after hooks. (Bug#13773) --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index abcf657806..7581b2a376 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-02-21 Glenn Morris + + * files.el (basic-save-buffer): Move check for existing parent + directory after hooks. (Bug#13773) + 2013-02-20 Stefan Monnier * simple.el (command-execute): Move from C. Add obsolete check. diff --git a/lisp/files.el b/lisp/files.el index f9ed65b8ac..f9d0251183 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4563,15 +4563,8 @@ 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-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. + (or buffer-file-name (let ((filename (expand-file-name (read-file-name "File to save in: " @@ -4628,7 +4621,14 @@ Before and after saving the buffer, this function runs (run-hook-with-args-until-success 'write-file-functions) ;; If a hook returned t, file is already "written". ;; Otherwise, write it the usual way now. - (setq setmodes (basic-save-buffer-1))) + (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"))) + (setq setmodes (basic-save-buffer-1)))) ;; Now we have saved the current buffer. Let's make sure ;; that buffer-file-coding-system is fixed to what ;; actually used for saving by binding it locally.