emacs-devel
[Top][All Lists]
Advanced

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

patch: write-file to arbitrary target directory


From: Eduard Wiebe
Subject: patch: write-file to arbitrary target directory
Date: Sat, 17 Nov 2007 02:09:34 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (berkeley-unix)

 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 via email to

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