bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#24150: 26.0.50; New command: dired-create-empty-file


From: Eli Zaretskii
Subject: bug#24150: 26.0.50; New command: dired-create-empty-file
Date: Fri, 27 Jul 2018 11:39:38 +0300

> From: Tino Calancha <tino.calancha@gmail.com>
> 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 <eliz@gnu.org> 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.





reply via email to

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