From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eduard Wiebe Newsgroups: gmane.emacs.devel Subject: patch: write-file to arbitrary target directory Date: Sat, 17 Nov 2007 02:09:34 +0100 Message-ID: <86r6ip7k4x.fsf@nirvana.pusto.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1195258284 6211 80.91.229.12 (17 Nov 2007 00:11:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 Nov 2007 00:11:24 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 17 01:11:28 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1ItBHR-0001JM-SM for ged-emacs-devel@m.gmane.org; Sat, 17 Nov 2007 01:11:26 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ItBHE-0004Jq-Fo for ged-emacs-devel@m.gmane.org; Fri, 16 Nov 2007 19:11:12 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ItBHA-0004J9-Su for emacs-devel@gnu.org; Fri, 16 Nov 2007 19:11:08 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ItBHA-0004Ip-8m for emacs-devel@gnu.org; Fri, 16 Nov 2007 19:11:08 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ItBHA-0004Ie-1R for emacs-devel@gnu.org; Fri, 16 Nov 2007 19:11:08 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1ItBH9-0001Ly-E4 for emacs-devel@gnu.org; Fri, 16 Nov 2007 19:11:07 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1ItBGz-0008FN-2a for emacs-devel@gnu.org; Sat, 17 Nov 2007 00:10:57 +0000 Original-Received: from p57b434f9.dip0.t-ipconnect.de ([87.180.52.249]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 17 Nov 2007 00:10:57 +0000 Original-Received: from usenet by p57b434f9.dip0.t-ipconnect.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 17 Nov 2007 00:10:57 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 61 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p57b434f9.dip0.t-ipconnect.de User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (berkeley-unix) Cancel-Lock: sha1:/vlEwT8R3m7r0htUj3PumLD4Ic4= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:83393 Archived-At: 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