From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#24150: 26.0.50; New command: dired-create-empty-file Date: Fri, 27 Jul 2018 11:39:38 +0300 Message-ID: <83r2jprs1h.fsf@gnu.org> References: <87mv8m3yya.fsf@calancha-pc> <83wp7mn3go.fsf@gnu.org> <97b67d5a-fc1e-47ea-b6b1-4154206ed5f9@default> <87bmbfwp4x.fsf@calancha-pc.dy.bbexcite.jp> <879bc31155c8718745f44321382e9ecb@webmail.orcon.net.nz> <87lgaa9uq8.fsf@calancha-pc.dy.bbexcite.jp> <83pnzi1dpy.fsf@gnu.org> <87va9661uy.fsf@calancha-pc.dy.bbexcite.jp> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1532680686 13114 195.159.176.226 (27 Jul 2018 08:38:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 27 Jul 2018 08:38:06 +0000 (UTC) Cc: psainty@orcon.net.nz, tzz@lifelogs.com, clement.pit@gmail.com, michael.albinus@gmx.de, 24150@debbugs.gnu.org, sdl.web@gmail.com To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jul 27 10:38:01 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fiyG9-0003Hk-JV for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Jul 2018 10:38:01 +0200 Original-Received: from localhost ([::1]:39745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiyIG-0006D5-4c for geb-bug-gnu-emacs@m.gmane.org; Fri, 27 Jul 2018 04:40:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiyIA-0006Cn-A5 for bug-gnu-emacs@gnu.org; Fri, 27 Jul 2018 04:40:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiyI6-0003ek-BC for bug-gnu-emacs@gnu.org; Fri, 27 Jul 2018 04:40:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54522) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fiyI6-0003eg-6P for bug-gnu-emacs@gnu.org; Fri, 27 Jul 2018 04:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fiyI5-0002pq-Rq for bug-gnu-emacs@gnu.org; Fri, 27 Jul 2018 04:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Jul 2018 08:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24150 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24150-submit@debbugs.gnu.org id=B24150.153268079210878 (code B ref 24150); Fri, 27 Jul 2018 08:40:01 +0000 Original-Received: (at 24150) by debbugs.gnu.org; 27 Jul 2018 08:39:52 +0000 Original-Received: from localhost ([127.0.0.1]:59540 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fiyHw-0002pO-01 for submit@debbugs.gnu.org; Fri, 27 Jul 2018 04:39:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52820) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fiyHu-0002pC-QT for 24150@debbugs.gnu.org; Fri, 27 Jul 2018 04:39:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiyHo-0003Zg-Ii for 24150@debbugs.gnu.org; Fri, 27 Jul 2018 04:39:45 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:42817) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiyHk-0003Z2-1V; Fri, 27 Jul 2018 04:39:40 -0400 Original-Received: from [176.228.60.248] (port=4701 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1fiyHj-0006L8-Eb; Fri, 27 Jul 2018 04:39:39 -0400 In-reply-to: <87va9661uy.fsf@calancha-pc.dy.bbexcite.jp> (message from Tino Calancha on Mon, 23 Jul 2018 12:57:09 +0900) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:148999 Archived-At: > From: Tino Calancha > Cc: bug-gnu-emacs-bounces+psainty=orcon.net.nz@gnu.org, psainty@orcon.net.nz, tzz@lifelogs.com, clement.pit@gmail.com, michael.albinus@gmx.de, 24150@debbugs.gnu.org, sdl.web@gmail.com > Date: Mon, 23 Jul 2018 12:57:09 +0900 > > Eli Zaretskii writes: > > > I was somewhat surprised to see how much > > code you needed. We have the capability of creating parent > > directories in 'make-directory', so I thought all we'd need for > > creating a new file is this two-step dance: > > > > . call make-directory to maybe create the file's parent directory > > . call write-region to create the file itself > > > > What did I miss that needs so many lines of code? > Right. Too much dance. > Updated the patch to follow your recomendation: Thanks, this is much better IMO. > +@deffn Command make-empty-file filename &optional parents > +This command creates an empty file named @var{filename}. > +As @code{make-directory}, this command creates parent directories > +if @var{parents} is non-@code{nil}. > +If @var{filename} already exists, then this command signal an error. ^^^^^^ "signals". And I would drop the "then" part, it is not needed here. > +(defun dired--find-topmost-parent-dir (filename) > + "Return the topmost nonexistent parent dir of FILENAME. > +FILENAME is a full file name." > + (let ((try filename) new) > + (while (and try (not (file-exists-p try)) (not (equal new try))) > + (setq new try > + try (directory-file-name (file-name-directory try)))) > + new)) What is the purpose of using this function in dired-create-empty-file? What you do with the result of this function doesn't seem to be reflected in the doc string of dired-create-empty-file. > +(defun make-empty-file (filename &optional parents) > + "Create an empty file FILENAME. > +Optional arg PARENTS, if non-nil then creates parent dirs as needed. "Optional arg PARENTS, if non-nil, means create parent dirs as needed." > +If called interactively, then PARENTS is non-nil." > + (interactive > + (let ((filename (read-file-name "Create empty file: "))) > + (list filename t))) > + (let ((paren-dir (file-name-directory filename))) > + (when paren-dir (make-directory paren-dir parents))) > + (if (and (file-exists-p filename) (null parents)) > + (signal 'file-already-exists `("File exists" ,filename) ) Shouldn't we check for file existing before creating the missing parent directories? Thanks.