unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: clement.pit@gmail.com
Cc: 24150@debbugs.gnu.org, tino.calancha@gmail.com
Subject: bug#24150: 25.1.50; New command: dired-create-empty-file
Date: Fri, 5 Aug 2016 15:03:10 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1608051501470.14285@calancha-pc> (raw)
In-Reply-To: <alpine.DEB.2.20.1608042223340.11938@calancha-pc>

[-- Attachment #1: Type: text/plain, Size: 3875 bytes --]


On Thu, 4 Aug 2016, Clément Pit--Claudel wrote:

>Ah, so it's different from touch. Is there already a command in dired
>that sets the access and modification time of a file? If not, maybe
>this command could do it? I'm not sure it's useful to have the command
>fail if the file exists. If you go that, maybe renaming the command to
>eg dired-touch would be useful? Although I see the parallel with
>dired-create-directory, so maybe it's fine.

'dired-do-touch' doesn't create a new file.
I use to create an empty file with
M-! touch new-file RET
Note this creates a new file in the current directory; it
desn't create non existing parens, for instance:
M-! touch new-paren/new-file RET
;; touch: cannot touch 'new-paren/new-file': No such file or directory

The command i am suggesting is a partner of 'dired-create-directory':
it also creates the paren dirs.

>I think there's a slight problem with this sentence.  Maybe
>*** New command 'dired-create-empty-file' (similar to
>'dired-create-directory') creates a new empty file;
>bound to 'M-+'.
Thanks a lot!

> Do you think this could be a defun instead of a macro?
Of course, it should be a defun!
Following is the corrected patch to dired-aux.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 4732d9c..f95e74e 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1888,25 +1888,47 @@ dired-dwim-target-defaults
        dired-dirs)))


-;;;###autoload
-(defun dired-create-directory (directory)
-  "Create a directory called DIRECTORY.
-If DIRECTORY already exists, signal an error."
-  (interactive
-   (list (read-file-name "Create directory: " 
(dired-current-directory))))
-  (let* ((expanded (directory-file-name (expand-file-name directory)))
-	 (try expanded) new)
-    (if (file-exists-p expanded)
-	(error "Cannot create directory %s: file exists" expanded))
+(defun dired--create-empty-file-or-directory (fname &optional 
create-file)
+  "Create an empty file or directory called FNAME.
+If FNAME already exists, signal an error.
+Optional arg CREATE-FILE if non-nil, then create a file.  Otherwise 
create
+a directory. "
+  (let* ((expanded (directory-file-name (expand-file-name fname)))
+         (parent (directory-file-name (file-name-directory expanded)))
+         (try expanded) new)
+    (when create-file
+      (setq try parent
+            new expanded))
+    (when (file-exists-p expanded)
+      (error "Cannot create file %s: file exists" expanded))
      ;; Find the topmost nonexistent parent dir (variable `new')
      (while (and try (not (file-exists-p try)) (not (equal new try)))
        (setq new try
-	    try (directory-file-name (file-name-directory try))))
-    (make-directory expanded t)
+            try (directory-file-name (file-name-directory try))))
+    (cond (create-file
+           (unless (file-exists-p parent)
+             (make-directory parent t))
+           (write-region "" nil expanded nil 0))
+          (t
+           (make-directory expanded t)))
      (when new
        (dired-add-file new)
        (dired-move-to-filename))))

+;;;###autoload
+(defun dired-create-directory (directory)
+  "Create a directory called DIRECTORY.
+If DIRECTORY already exists, signal an error."
+  (interactive (list (read-file-name "Create directory: ")))
+  (dired--create-empty-file-or-directory directory))
+
+;;;###autoload
+(defun dired-create-empty-file (file)
+  "Create an empty file called FILE.
+If FILE already exists, signal an error."
+  (interactive (list (read-file-name "Create empty file: ")))
+  (dired--create-empty-file-or-directory file 'create-file))
+
  (defun dired-into-dir-with-symlinks (target)
    (and (file-directory-p target)
         (not (file-symlink-p target))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  parent reply	other threads:[~2016-08-05  6:03 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 13:25 bug#24150: 25.1.50; New command: dired-create-empty-file Tino Calancha
2016-08-04 13:54 ` Clément Pit--Claudel
2016-08-04 16:29 ` Leo Liu
2016-08-04 17:13   ` Ted Zlatanov
2016-08-04 17:29     ` Drew Adams
2016-08-05  6:03 ` Tino Calancha [this message]
2016-08-05 14:48   ` Drew Adams
2016-08-06 12:38     ` Tino Calancha
2016-08-05  6:07 ` Tino Calancha
2017-05-03  8:23 ` Tino Calancha
2017-07-03  4:51 ` bug#24150: 26.0.50; " Tino Calancha
2017-07-03 14:24   ` Eli Zaretskii
2017-07-03 15:04     ` Tino Calancha
2017-07-03 16:33       ` Eli Zaretskii
2017-07-03 20:18         ` Thien-Thi Nguyen
2017-07-07 13:13         ` Ted Zlatanov
2017-07-07 13:17           ` Drew Adams
2017-07-07 13:31             ` Ted Zlatanov
2017-07-03 15:12     ` Drew Adams
2017-07-05 18:28   ` Eli Zaretskii
2017-07-05 19:34     ` Drew Adams
2017-07-07  5:36       ` Tino Calancha
2017-07-07 11:11         ` Drew Adams
2018-07-10  7:01           ` Tino Calancha
2018-07-10  7:42             ` Phil Sainty
2018-07-17  7:39               ` Tino Calancha
2018-07-20  9:03                 ` Eli Zaretskii
2018-07-23  3:57                   ` Tino Calancha
2018-07-27  8:39                     ` Eli Zaretskii
2018-07-31  4:47                       ` Tino Calancha
2018-07-31 16:20                         ` Eli Zaretskii
2018-08-01  5:16                           ` Tino Calancha
2018-08-01  6:24                             ` Eli Zaretskii
2018-08-01  7:13                               ` Tino Calancha
2018-08-01  8:56                                 ` Eli Zaretskii
2018-08-01  9:31                                   ` Tino Calancha
2018-08-01 11:45                                     ` Eli Zaretskii
2018-08-02  4:34                                       ` Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1608051501470.14285@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=24150@debbugs.gnu.org \
    --cc=clement.pit@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).