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: Thu, 4 Aug 2016 22:25:10 +0900 (JST) Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1470317185 4127 195.159.176.226 (4 Aug 2016 13:26:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Aug 2016 13:26:25 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) To: 24150@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 04 15:26:21 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 1bVIfE-0000I2-Dc for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Aug 2016 15:26:20 +0200 Original-Received: from localhost ([::1]:39923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVIfB-0006NM-00 for geb-bug-gnu-emacs@m.gmane.org; Thu, 04 Aug 2016 09:26:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVIf1-0006LU-9f for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:26:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVIew-0004FQ-CA for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:26:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58015) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVIew-0004FG-8t for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bVIew-0003UZ-2j for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Aug 2016 13:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24150 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.147031713313384 (code B ref -1); Thu, 04 Aug 2016 13:26:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Aug 2016 13:25:33 +0000 Original-Received: from localhost ([127.0.0.1]:55312 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVIeS-0003Tn-TP for submit@debbugs.gnu.org; Thu, 04 Aug 2016 09:25:33 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36397) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVIeQ-0003TW-Mi for submit@debbugs.gnu.org; Thu, 04 Aug 2016 09:25:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVIeK-00049m-3l for submit@debbugs.gnu.org; Thu, 04 Aug 2016 09:25:25 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:58000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVIeK-00049d-02 for submit@debbugs.gnu.org; Thu, 04 Aug 2016 09:25:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVIeH-0005iy-Cq for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:25:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bVIeC-000494-DN for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:25:21 -0400 Original-Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]:35608) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bVIeC-00048z-1A for bug-gnu-emacs@gnu.org; Thu, 04 Aug 2016 09:25:16 -0400 Original-Received: by mail-pf0-x22a.google.com with SMTP id x72so87064057pfd.2 for ; Thu, 04 Aug 2016 06:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:subject:message-id:user-agent:mime-version; bh=pthZo0fAiE3ZApUp6ivfgTwSk2NcFBb0cBRnV29iD0I=; b=X1bZqkoGUlER64OSPAbQSG2kQxOf0v/1WQutp4yh3xRh+wWy316oxBOd77oaJPbOrj gvPWdkoOLenmV78O/1M8cbgLqkK4YWpOIWgrFbvOd/4cw8Woy5RedYJKzCZcjT6RS6bj w3QAZQUuH9lXCk/vF/tBSfssv+eOikOcIsfbGKrxHBvJaE1m6YPUX1dwi96ug6tnyaCq xYm9x8b8s8S3XOPO08fzqFtHqGpC+SuSO3OxDk/ZoEMWGbAcaOS4Q7rIxwr10af6Dgw7 7ugqFsDYyTuCBl98mETMOifbXJ/YMvkyv2xqaidCHe/A8ujinxOopiBxSzCsLlA9L0fc yc0g== 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:subject:message-id:user-agent :mime-version; bh=pthZo0fAiE3ZApUp6ivfgTwSk2NcFBb0cBRnV29iD0I=; b=lt7mQnvZesNN0ZQ1Gd/NCu34AzQdkZ1FUmTQglVN9hFWFbqoTYHkOahmZY8FgLN0hQ IcOQ6RX+XntpGu3qv41cbfImgNguxJa7Z7IH5jcgAZuoNcjCPPm56O0qqizq5EHyFg34 YzxEM4PSMvo/KSuIJxF8i0RoqU+w3WwwpIwaR6nC1LH4ddjuZ3d9hM8onS0RbkK0xJQ+ 9PXoEHSUee/iV9sr9TulMlQ5wLEFRksX1cMcSai502L62WiYm0KTE15QDVq2tWotxj/b r0K4HsJZZsFQslZaNsK3/aMatwCrX9Hj986A6HwuHuo/j+mKUlwj1m8IBHNx9xhITRiv toZg== X-Gm-Message-State: AEkoouso0Jo5nIA8SuhRhlpd0hMoKXmRiqyMeUtCV4yBzYgS1o8KLZ124GE76JuoIIvLPA== X-Received: by 10.98.35.7 with SMTP id j7mr126387451pfj.39.1470317114678; Thu, 04 Aug 2016 06:25:14 -0700 (PDT) Original-Received: from MAR89-117.kek.jp (MAR89-117.kek.jp. [130.87.89.117]) by smtp.gmail.com with ESMTPSA id e10sm20590580pay.39.2016.08.04.06.25.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 06:25:14 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:121819 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. Following patch propose a new command 'dired-create-empty-file' bound to 'M-+'. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 96b5bfe9f33e7fea5296f83649dd4b6a48bafb06 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Thu, 4 Aug 2016 22:07:00 +0900 Subject: [PATCH] New command dired-create-empty-file * lisp/dired-aux.el (dired--create-empty-file-or-directory): New macro to create a new empty file or directory. (dired-create-directory): Use it. (dired-create-empty-file): New command; as 'dired-create-directory' but it creates an empty file instead of a dir. * lisp/dired.el (dired-mode-map): Bind 'dired-create-empty-file' to 'M-+'. * doc/emacs/dired.texi: Document the new command in the manual. * etc/NEWS: Add entry for this new feature. --- doc/emacs/dired.texi | 6 ++++++ etc/NEWS | 5 +++++ lisp/dired-aux.el | 50 ++++++++++++++++++++++++++++++++++++-------------- lisp/dired.el | 1 + 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 2cda51a..c2de114 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -1410,6 +1410,12 @@ Misc Dired Features directory name, and creates that directory. It signals an error if the directory already exists. +@kindex M-+ @r{(Dired)} +@findex dired-create-empty-file + The command @kbd{M-+} (@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 fadf4c2..394b9f8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -249,6 +249,11 @@ whose content matches a regexp; bound to '% g'. ** Dired +++ +*** A new command 'dired-create-empty-file' similar as +'dired-create-directory' but it creates a new empty file; +bound to 'M-+'. + ++++ *** A New option 'dired-always-read-filesystem' default to nil. If non-nil, buffers visiting files are reverted before search them; for instance, in 'dired-mark-files-containing-regexp' a non-nil value diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 4732d9c..84b0c35 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1888,24 +1888,46 @@ dired-dwim-target-defaults dired-dirs))) +(defmacro 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)))) + (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-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)) - ;; 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) - (when new - (dired-add-file new) - (dired-move-to-filename)))) + (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) diff --git a/lisp/dired.el b/lisp/dired.el index 7ead087..df5a61c 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1554,6 +1554,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 "\M-+" 'dired-create-empty-file) ;; moving (define-key map "<" 'dired-prev-dirline) (define-key map ">" 'dired-next-dirline) -- 2.8.1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 25.1.50 (x86_64-pc-linux-gnu, GTK+ Version 3.20.6) of 2016-08-03 built Repository revision: 7f9721d3990155bae83e4e4840f0ff4913868d50