unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: emacs-devel <emacs-devel@gnu.org>
Subject: save-buffer when directory doesn't exist
Date: Sat, 10 Mar 2007 10:43:56 +0100	[thread overview]
Message-ID: <45F27DDC.9080006@gmx.at> (raw)

[-- Attachment #1: Type: text/plain, Size: 859 bytes --]

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.

[-- Attachment #2: files.patch --]
[-- Type: text/plain, Size: 1428 bytes --]

*** 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

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

             reply	other threads:[~2007-03-10  9:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-10  9:43 martin rudalics [this message]
2007-03-20  8:09 ` save-buffer when directory doesn't exist Jason Spiro
2007-03-20  9:46   ` martin rudalics
2007-04-06 23:38     ` Jason Spiro
2007-04-07  7:33       ` martin rudalics
2007-04-08 21:42         ` Jason Spiro
2007-04-09  8:50           ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45F27DDC.9080006@gmx.at \
    --to=rudalics@gmx.at \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).