all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* patch: write-file to arbitrary target directory
@ 2007-11-17  1:09 Eduard Wiebe
  2007-11-17  1:34 ` Juri Linkov
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Eduard Wiebe @ 2007-11-17  1:09 UTC (permalink / raw)
  To: emacs-devel


 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

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

end of thread, other threads:[~2007-11-22  2:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-17  1:09 patch: write-file to arbitrary target directory Eduard Wiebe
2007-11-17  1:34 ` 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

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.