emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

save-buffer when directory doesn't exist


From: martin rudalics
Subject: save-buffer when directory doesn't exist
Date: Sat, 10 Mar 2007 10:43:56 +0100
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Assume I modify *scratch* and try to `save-buffer' it as ".../bar/foo".
(I know `write-file' should be used for this purpose but `save-buffer'
offers the service as well.)  Assume further, I mistype the name as
".../baz/foo" where the subdirectory "baz" does not exist.  Emacs will
complain as:

basic-save-buffer-2: .../baz/foo: no such directory

which is misleading since ".../baz/foo" is supposed to be a file.

Assume now I notice my mistake and want to `save-buffer' *scratch* in
the existing directory ".../bar/".  Emacs will insist on storing my
buffer as ".../baz/foo" and continue telling me that such a directory
doesn't exist.

After a while `auto-save-mode' may kick in and add to my confusion by
complaining

Auto-saving foo: Opening output file: no such file or directory, .../baz/#foo#

This confusion could be relieved by the attached patch.
*** files.el    Fri Mar  9 07:48:34 2007
--- files.el    Sat Mar 10 10:38:28 2007
***************
*** 3599,3606 ****
                  (setq buffer-new-name (buffer-name buf))
                  (kill-buffer buf))
                (rename-buffer buffer-new-name)))
!         ;; 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)))
--- 3599,3607 ----
                  (setq buffer-new-name (buffer-name buf))
                  (kill-buffer buf))
                (rename-buffer buffer-new-name)))
!         ;; If buffer has no file name or the visited file is not writable, ask
!         ;; user for one.
!         (or (and buffer-file-name (file-writable-p buffer-file-name))
              (let ((filename
                     (expand-file-name
                      (read-file-name "File to save in: ") nil)))
***************
*** 3681,3687 ****
          (if (not (file-directory-p dir))
              (if (file-exists-p dir)
                  (error "%s is not a directory" dir)
!               (error "%s: no such directory" buffer-file-name))
            (if (not (file-exists-p buffer-file-name))
                (error "Directory %s write-protected" dir)
              (if (yes-or-no-p
--- 3682,3688 ----
          (if (not (file-directory-p dir))
              (if (file-exists-p dir)
                  (error "%s is not a directory" dir)
!               (error "%s: no such directory" dir))
            (if (not (file-exists-p buffer-file-name))
                (error "Directory %s write-protected" dir)
              (if (yes-or-no-p

reply via email to

[Prev in Thread] Current Thread [Next in Thread]