all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* save-buffer when directory doesn't exist
@ 2007-03-10  9:43 martin rudalics
  2007-03-20  8:09 ` Jason Spiro
  0 siblings, 1 reply; 7+ messages in thread
From: martin rudalics @ 2007-03-10  9:43 UTC (permalink / raw)
  To: emacs-devel

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-04-09  8:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-10  9:43 save-buffer when directory doesn't exist martin rudalics
2007-03-20  8:09 ` 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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.