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: 26.0.50; New command: dired-create-empty-file Date: Mon, 03 Jul 2017 13:51:25 +0900 Message-ID: <87mv8m3yya.fsf@calancha-pc> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1499057576 13622 195.159.176.226 (3 Jul 2017 04:52:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 3 Jul 2017 04:52:56 +0000 (UTC) Cc: Ted Zlatanov , tino.calancha@gmail.com, =?UTF-8?Q?Cl=C3=A9ment?= Pit--Claudel , Leo Liu To: 24150@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jul 03 06:52:48 2017 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 1dRtLn-0002uQ-1c for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Jul 2017 06:52:43 +0200 Original-Received: from localhost ([::1]:60335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRtLs-0004Tx-E0 for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Jul 2017 00:52:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRtLC-00047O-1j for bug-gnu-emacs@gnu.org; Mon, 03 Jul 2017 00:52:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRtL8-00026a-2I for bug-gnu-emacs@gnu.org; Mon, 03 Jul 2017 00:52:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46651) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dRtL7-00026H-TH for bug-gnu-emacs@gnu.org; Mon, 03 Jul 2017 00:52:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dRtL7-00044b-NI for bug-gnu-emacs@gnu.org; Mon, 03 Jul 2017 00:52:01 -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: Mon, 03 Jul 2017 04:52: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.149905749815626 (code B ref 24150); Mon, 03 Jul 2017 04:52:01 +0000 Original-Received: (at 24150) by debbugs.gnu.org; 3 Jul 2017 04:51:38 +0000 Original-Received: from localhost ([127.0.0.1]:49328 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRtKj-00043y-T5 for submit@debbugs.gnu.org; Mon, 03 Jul 2017 00:51:38 -0400 Original-Received: from mail-pf0-f177.google.com ([209.85.192.177]:34847) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dRtKi-00043j-24 for 24150@debbugs.gnu.org; Mon, 03 Jul 2017 00:51:36 -0400 Original-Received: by mail-pf0-f177.google.com with SMTP id c73so94088511pfk.2 for <24150@debbugs.gnu.org>; Sun, 02 Jul 2017 21:51:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version; bh=dp/ZewI2AOQbme8IrkLZz2cVlJDi6s17OAGRlWnStdI=; b=ZdDoar/OcV3kMU+ZbNt2deZiowF8f/ZGkZEl+ldoPyBh8IK4cKRR7JDAykcrtWWutW y++qvqmkHpCqjl+ORzbQgIRh7Xoaim+aAWcXb7gAHfbrJTvg88IDtY6TEjjotA3Fcsyw zHswt22Y2DOvUavniVZeA/v1txQSYvM5HdMGi1v8geKuuTrAFcYFN3woQmtzaCMc3f+B RlUooGYq/5VK21arRmFx/DEX3OXhWECOKWkMlp2yT7tz3fZD9I/ZjucSldUNesD4ZKAk ZRziAuNmxiWw6uqc03Xlw125S0C4gCg5i7sIxzaU7b7R2X6mtDzHS3miQ5V28tSbbbe8 wAbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=dp/ZewI2AOQbme8IrkLZz2cVlJDi6s17OAGRlWnStdI=; b=tCO+h7fCkoEx4/18nMyq0bmn7SJt1G0yv8uPYj36g70q7I/R5ac9hUi1v9c2S6I2iM ZKFHog0m4iR9K1DoXqbf539xSzzg2BE2W1q2D3NSm+kMv8OEUQh1wt11uEjbBJDAhBUU v+XcpwGdyrK13PhdORzwkYCNhvhVNcGQ5bJ2OdvSo0Uy1JrfzbK0ZP28tuqv+ocNaHoV +6IbnR2JeWKQBS1mkdB/doVD3NsLsWOt+pjhhCpBXygpHYxteqKmARvWWvofN3IGLAKM HEbtBALBZ3Ta0ykfbKteJaOl1Q/jbA70vj2a0G40sD5V7xTIPkCNaN/O1z3XYF5vgDzD YpfA== X-Gm-Message-State: AIVw113WQWqlZIVzq/fFddeDQgSv+lOJ323+xfepPG+WowQTXW8pcvZr 8MQ3YuYdf5W06w== X-Received: by 10.84.136.129 with SMTP id 1mr8556755pll.39.1499057490218; Sun, 02 Jul 2017 21:51:30 -0700 (PDT) Original-Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id t78sm34638878pfa.48.2017.07.02.21.51.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 02 Jul 2017 21:51:29 -0700 (PDT) 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:134111 Archived-At: >> Hi all, >> >> It might be useful having a Dired command creating >> an empty file with a name provided by the user; something >> like 'dired-create-directory' ('+') but for files. >It seems people is not interested on this feature, so i am closing the report. After i found the following threads: https://stackoverflow.com/questions/20300137/how-to-create-new-file-from-dired-mode https://stackoverflow.com/questions/2592095/how-do-i-create-an-empty-file-in-emacs and considering the significant number of views they have, i'd like to reopen this issue. 1. In my config i've bound the new command to 'M-+'. 2. In the threads above they suggest the keybindings 'c' and '_'. 'c' is already bound to `dired-do-compress-to', so i propose to bind the new command to '_' (unless you have a better proposal). If there are no objections, i would like to apply the following patch in a few days: --8<-----------------------------cut here---------------start------------->8--- commit 2661c4957b9ef90a2282a697dc5db3fab7e252b8 Author: Tino Calancha Date: Mon Jul 3 13:36:09 2017 +0900 New command dired-create-empty-file Add a dired command, similar to 'dired-create-directory', to create an empty file (Bug#24150). * lisp/dired-aux.el (dired--create-empty-file-or-directory): New defun. (dired-create-directory): Use it. (dired-create-empty-file): New command. * lisp/dired.el (dired-mode-map): Bind 'dired-create-empty-file' to '_'. * doc/emacs/dired.texi: Document the new command in the manual. ; * etc/NEWS: Announce it. Fix a previous Dired entry. diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 28cb51d88b..94a122e7eb 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -1416,6 +1416,12 @@ Misc Dired Features directory name, and creates that directory. It signals an error if the directory already exists. +@kindex _ @r{(Dired)} +@findex dired-create-empty-file + Likewise, @kbd{_} (@code{dired-create-empty-file}) reads a +file name, and creates an empty file with that name. It signals +an error if the file already exists. + @cindex searching multiple files via Dired @kindex M-s a C-s @r{(Dired)} @kindex M-s a M-C-s @r{(Dired)} diff --git a/etc/NEWS b/etc/NEWS index 39c88c60e7..69e8733d73 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -500,8 +500,12 @@ properties as intact as possible. * Changes in Specialized Modes and Packages in Emacs 26.1 ** Dired -You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', it gets replaced -by the current file name. + +*** New command 'dired-create-empty-file' (similar to +'dired-create-directory') creates a new empty file; bound to '_'. + +*** You can now use '`?`' in 'dired-do-shell-command'; as ' ? ', +it gets replaced by the current file name. *** html2text is now marked obsolete. diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index e454775858..9c3585d669 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1958,25 +1958,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)))) diff --git a/lisp/dired.el b/lisp/dired.el index 0c1f3e4af6..291c545e87 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1557,6 +1557,7 @@ dired-mode-map (define-key map "x" 'dired-do-flagged-delete) (define-key map "y" 'dired-show-file-type) (define-key map "+" 'dired-create-directory) + (define-key map "_" 'dired-create-empty-file) ;; moving (define-key map "<" 'dired-prev-dirline) (define-key map ">" 'dired-next-dirline) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 7, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-07-03 Repository revision: bc3dcd524dfb5c889ed017c093eaf028596fc35c