From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#24150: 25.1.50; New command: dired-create-empty-file Date: Fri, 5 Aug 2016 15:03:10 +0900 (JST) Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="8323329-1908891417-1470376993=:14285" X-Trace: blaine.gmane.org 1470377289 27374 195.159.176.226 (5 Aug 2016 06:08:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 5 Aug 2016 06:08:09 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 24150@debbugs.gnu.org, tino.calancha@gmail.com To: clement.pit@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 05 08:08:05 2016 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 1bVYIf-0006WG-8F for geb-bug-gnu-emacs@m.gmane.org; Fri, 05 Aug 2016 08:08:05 +0200 Original-Received: from localhost ([::1]:42939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVYIb-0003SF-UR for geb-bug-gnu-emacs@m.gmane.org; Fri, 05 Aug 2016 02:08:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVYEn-0000Pk-Lq for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2016 02:04:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVYEk-0000Hz-AK for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2016 02:04:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVYEk-0000Hu-6w for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2016 02:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bVYEk-0004MP-21 for bug-gnu-emacs@gnu.org; Fri, 05 Aug 2016 02:04:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 05 Aug 2016 06:04:02 +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.147037701816726 (code B ref 24150); Fri, 05 Aug 2016 06:04:02 +0000 Original-Received: (at 24150) by debbugs.gnu.org; 5 Aug 2016 06:03:38 +0000 Original-Received: from localhost ([127.0.0.1]:56057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVYEM-0004Li-H7 for submit@debbugs.gnu.org; Fri, 05 Aug 2016 02:03:38 -0400 Original-Received: from mail-pa0-f66.google.com ([209.85.220.66]:34422) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVYEK-0004LL-Fc for 24150@debbugs.gnu.org; Fri, 05 Aug 2016 02:03:36 -0400 Original-Received: by mail-pa0-f66.google.com with SMTP id hh10so18807632pac.1 for <24150@debbugs.gnu.org>; Thu, 04 Aug 2016 23:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:cc:subject:message-id:user-agent:mime-version; bh=uQuImid+RBLbGNvXwJLcYEq/P7dnpI5BDQdlTb8G33A=; b=u7B674p7TWLBC8aNWXo1wqlUvard7zu5AoIj59O2pijoT/86xDRKUj8X0XLo3vddvN q8x5YZAVZc6V8feKG/q1MpI4k7IMCx0koUxy6Zv2wXMjV8W7pWSYAb4HDEv0EUkR8i/5 PpP2wlvRSLmFn5uMDMUpc/f70gi7ybX5chPUqxNmsP0qAQ0Hc4W/oH851vO3MXdDPVnF 5iVrfk8CRWTB/FtJ9bI68ieJAmB/wgIpn3C5EtRm2GcVORbtSLZEf66Z/k4KNDbT0fLB CBIN3N4H4NK4SeOGCMOUGapuzRB3aTmXNRxXB7XVJQURWfgi1iZgya5i5dEggudVzW9x CAMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:message-id:user-agent :mime-version; bh=uQuImid+RBLbGNvXwJLcYEq/P7dnpI5BDQdlTb8G33A=; b=I7DQh6rbyKZLcJY95TDgO7MI5YN9+oOeptRmp7RXDPCXdEqKYn3OQZVgzGk0fmVW2M LIz+k9Zf+SpbMSleUJL5tCdggykZshNxPRyhpAfKxy9rEoJVlcROgjXbszD0hTfvNqoD JN/J3KE7fwJh5diD3NdCdthYeGqK/xIj7153Sr5ZYaKLUgtHMYhb7+VSHVZhJ70+/Bs4 FU4wFFzFWjpCkqsZoWh2PosU6T040DuIPbxWJH8ZdNnSj7s0amt4occX9xDWZ5xlisTY AuRnwzHsmsfh4T4E9+vkN604zQvaH0lJVxRgDzvKpc+0rIMpFtVmq507e7ByEzuW+g7A 9L+g== X-Gm-Message-State: AEkoousiSdLWZu6u+Ldxo62+XJE56MNHM4aAtMX2QmcTwbymxombGlHb2Pgqzn+VZb2TqQ== X-Received: by 10.66.25.135 with SMTP id c7mr30343453pag.24.1470376995916; Thu, 04 Aug 2016 23:03:15 -0700 (PDT) Original-Received: from MAR89-117.kek.jp (MAR89-117.kek.jp. [130.87.89.117]) by smtp.gmail.com with ESMTPSA id f6sm24562567pfa.17.2016.08.04.23.03.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 23:03:14 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc 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:121847 Archived-At: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1908891417-1470376993=:14285 Content-Type: text/plain; format=flowed; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT 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)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; --8323329-1908891417-1470376993=:14285--