all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eduard Wiebe <usenet@pusto.de>
To: emacs-devel@gnu.org
Subject: patch: write-file to arbitrary target directory
Date: Sat, 17 Nov 2007 02:09:34 +0100	[thread overview]
Message-ID: <86r6ip7k4x.fsf@nirvana.pusto.de> (raw)


 Hello,

This patch improves 'write-file' by creating  all parent directories of
target file (in spirit of proposal by Juri[1]).

Any comments?

Index: files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.941
diff -c -r1.941 files.el
*** files.el	16 Nov 2007 08:03:45 -0000	1.941
--- files.el	16 Nov 2007 23:51:19 -0000
***************
*** 3086,3099 ****
     (list (if buffer-file-name
  	     (read-file-name "Write file: "
  			     nil nil nil nil)
! 	   (read-file-name "Write file: " default-directory
! 			   (expand-file-name
! 			    (file-name-nondirectory (buffer-name))
! 			    default-directory)
! 			   nil nil))
  	 (not current-prefix-arg)))
    (or (null filename) (string-equal filename "")
        (progn
  	;; If arg is just a directory,
  	;; use the default file name, but in that directory.
  	(if (file-directory-p filename)
--- 3086,3107 ----
     (list (if buffer-file-name
  	     (read-file-name "Write file: "
  			     nil nil nil nil)
! 	   (let ((dir  (file-name-directory (buffer-name)))
! 		 (file (file-name-nondirectory (buffer-name))))
! 	     (read-file-name "Write file: "
! 			     dir (expand-file-name file dir) nil file)))
  	 (not current-prefix-arg)))
    (or (null filename) (string-equal filename "")
        (progn
+ 	;; If directory of file is not existent, create it with all parents.
+ 	(let ((dir (file-name-directory filename)))
+ 	  (when (and dir (not (file-exists-p dir)))
+ 	    (and confirm
+ 		 (or (y-or-n-p
+ 		      (format "Directory `%s' does not exists; create? " dir))
+ 		     (error "Canceled")))
+ 	    (make-directory dir 'parents)))
+ 
  	;; If arg is just a directory,
  	;; use the default file name, but in that directory.
  	(if (file-directory-p filename)


-------
[1]  http://article.gmane.org/gmane.emacs.devel/82779/match=dired+create+directory+arbitrary+depth

-- 
Eduard Wiebe

             reply	other threads:[~2007-11-17  1:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-17  1:09 Eduard Wiebe [this message]
2007-11-17  1:34 ` patch: write-file to arbitrary target directory Juri Linkov
2007-11-17  4:28 ` Stefan Monnier
2007-11-17  9:22   ` Eli Zaretskii
2007-11-17 13:14     ` Eduard Wiebe
2007-11-17 12:36       ` Eli Zaretskii
2007-11-17 13:03         ` Thien-Thi Nguyen
2007-11-17 22:04         ` Eduard Wiebe
2007-11-17 23:31   ` Richard Stallman
2007-11-17  9:34 ` martin rudalics
2007-11-17 13:15   ` Eduard Wiebe
2007-11-17 17:42 ` Richard Stallman
2007-11-17 23:22   ` Eduard Wiebe
     [not found]   ` <861waobh7m.fsf@nirvana.pusto.de>
2007-11-18 13:01     ` Richard Stallman
2007-11-19  0:01       ` Eduard Wiebe
2007-11-22  2:28         ` Richard Stallman

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

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

  git send-email \
    --in-reply-to=86r6ip7k4x.fsf@nirvana.pusto.de \
    --to=usenet@pusto.de \
    --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 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.