* lisp/files.el (basic-save-buffer): Move check for existing parent directory
authorGlenn Morris <rgm@gnu.org>
Thu, 21 Feb 2013 02:44:06 +0000 (21:44 -0500)
committerGlenn Morris <rgm@gnu.org>
Thu, 21 Feb 2013 02:44:06 +0000 (21:44 -0500)
after hooks.  (Bug#13773)

lisp/ChangeLog
lisp/files.el

index abcf657..7581b2a 100644 (file)
@@ -1,3 +1,8 @@
+2013-02-21  Glenn Morris  <rgm@gnu.org>
+
+       * files.el (basic-save-buffer): Move check for existing parent
+       directory after hooks.  (Bug#13773)
+
 2013-02-20  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * simple.el (command-execute): Move from C.  Add obsolete check.
index f9ed65b..f9d0251 100644 (file)
@@ -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.