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#27940: Recursively delete dir34? (yes, no, all, quit) Date: Fri, 04 Aug 2017 23:33:51 +0900 Message-ID: <871sorz9kg.fsf@calancha-pc> References: <87o9rwxmfz.fsf@jidanni.org> <87r2wrkacy.fsf@calancha-pc> <83a83fybrc.fsf@gnu.org> <87vam365q2.fsf@calancha-pc> <834ltnxzyz.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1501857347 5227 195.159.176.226 (4 Aug 2017 14:35:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Aug 2017 14:35:47 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 27940@debbugs.gnu.org, jidanni@jidanni.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 04 16:35:42 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 1dddhU-000126-C2 for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 16:35:40 +0200 Original-Received: from localhost ([::1]:34519 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dddha-0003NS-F9 for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 10:35:46 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dddh8-00033r-ND for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 10:35:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dddgt-0002Fl-6c for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 10:35:18 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39243) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dddgt-0002FP-1b for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 10:35:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dddgs-0002J0-Jr for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 10:35: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: Fri, 04 Aug 2017 14:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27940 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27940-submit@debbugs.gnu.org id=B27940.15018572458795 (code B ref 27940); Fri, 04 Aug 2017 14:35:02 +0000 Original-Received: (at 27940) by debbugs.gnu.org; 4 Aug 2017 14:34:05 +0000 Original-Received: from localhost ([127.0.0.1]:41920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dddfw-0002Hl-Hf for submit@debbugs.gnu.org; Fri, 04 Aug 2017 10:34:04 -0400 Original-Received: from mail-pg0-f45.google.com ([74.125.83.45]:36008) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dddfv-0002HH-0N for 27940@debbugs.gnu.org; Fri, 04 Aug 2017 10:34:03 -0400 Original-Received: by mail-pg0-f45.google.com with SMTP id v77so8754531pgb.3 for <27940@debbugs.gnu.org>; Fri, 04 Aug 2017 07:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=zEf3I+Ndh1HkBzO5qQlH1WZBj2NlHeSaG02N/ZBp8eM=; b=l9aF+w/pU/8MQtnwNeEDEfbbW/0BGJS58IDVnoSNEAvyYaFjc0BcHb6VsGdeT+FmfU SeTNFe/Uj3S1JWJPi9UKG491gV41TSzN7wk9JQ8WrGtLYwXcj7MyGDt1o0oa4+R0yYWs PGuQeFBTtlH2a+fkvcA673brMnYd7lLMzL4MH/94d67D8b6BVt2Wk9aQpRdpjXngUJBn j9UbRLZlrCJYXUfhT6Z+j/HDeGNdcO3W3oIACq+pXIlMZO3cb08EC/sWc4iZWkH6l/lr 5ksXtODEAukZe8/FGfD8FkfMJ23Savqsxnf+Te2JTYYc6mmNBwkjIwCCIr7AObPddZLd DjAw== 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:references:date:in-reply-to :message-id:user-agent:mime-version; bh=zEf3I+Ndh1HkBzO5qQlH1WZBj2NlHeSaG02N/ZBp8eM=; b=Gzfo1NcObo9PNxqEtvPou30KpzXbfnEcOAUQXmqgP0gOymJMd9Hn0RgPT1kCcwfp0P QgS2o6JDv6e2HWNfks4O44A+r6KPvedwLmVMDl9mhpZmCF1hLRDNMGfm/cWrkI3rorAe x+N6b2AbNSYpvE1ysD/PjTlQr1fimXm2WDQw9MZRiAVwqShODj23GqzMgU8Ym25MvBWB 2dnpMDLGjIhtjW8LeO9DRuv9sbe0FGaGkEoujznNGeL+6RuNaaKKbo8SDzmymIttxuIu X0Ku/ED1FvsbvaLnH5C4UoD4r/FtlVHpXAyTHhD/v8AcQWVsUkEDaolEwMGxEwPaRmGO dHKQ== X-Gm-Message-State: AIVw110WZNXsIt2pyngkecbagr/YtzgJw5zteUA2HV0LCP/9WCsG6925 NLoJWxFgjd9Vag== X-Received: by 10.99.114.20 with SMTP id n20mr2506659pgc.451.1501857236810; Fri, 04 Aug 2017 07:33:56 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id 133sm4272382pgc.19.2017.08.04.07.33.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2017 07:33:56 -0700 (PDT) In-Reply-To: <834ltnxzyz.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 04 Aug 2017 15:46:28 +0300") 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:135342 Archived-At: Eli Zaretskii writes: > Shouldn't the valid-answers be "yes" and "no", not "y" and "n", for > backward compatibility? Yes, they should. > >> + (completing-read (format "Recursively %s %s? [y, n, !, q] " > > Maybe the "!" and "q" parts should be explained? Or maybe just use > "yes", "no", "all", and "quite", which are self-explanatory? Look the updated patch; it's a mix: 1. uses 'yes', 'no' 2. '!', 'q', 'help' This is similar like `query-replace' does (there is used '!', 'q', and '?'). With 'help', a Help buffer is shown with a help message. > > This warrants a NEWS entry, I think. I also wonder whether we should > describe this in the user manual, under "Dired Deletion". I did. --8<-----------------------------cut here---------------start------------->8--- commit a883db5e05364bd7a76138642d39b296266ff0a1 Author: Tino Calancha Date: Fri Aug 4 23:26:30 2017 +0900 dired-do-delete: Allow to delete dirs recursively without prompts * lisp/dired.el (dired-delete-file): Accept 2 additional answers: '!', to delete all directories recursively and no prompt anymore. 'q', to cancel the directory deletions (Bug#27940). Show help message when user inputs 'help'. (dired-do-flagged-delete): Bind locally dired-recursive-deletes so that we can overwrite its global value. Wrapp the loop within a catch '--delete-cancel to catch when the user abort the directtry deletion. * doc/emacs/dired.texi (Dired Deletion): Update manual. * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 26.1): Announce this change. diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 150ac8427a..5eb066d927 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -236,6 +236,14 @@ Dired Deletion @code{dired-recursive-deletes} is non-@code{nil}, then Dired can delete nonempty directories including all their contents. That can be somewhat risky. +Even if you have set @code{dired-recursive-deletes} to @code{nil}, +you might want sometimes to delete recursively directories +without being asked for confirmation for all of them. This is handy +when you have marked many directories for deletion and you are very +sure that all of them can safely being deleted. For every nonempty +directory you are asked for confirmation; if you answer @code{!}, +then all the remaining directories will be deleted without more +questions. @vindex delete-by-moving-to-trash If you change the variable @code{delete-by-moving-to-trash} to diff --git a/etc/NEWS b/etc/NEWS index b72793dec0..dcac7d5e41 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -611,6 +611,10 @@ paragraphs, for the purposes of bidirectional display. ** Dired +++ +*** You can answer '!' in 'dired-do-delete' to delete recursively all +remaining directories without more prompts. + ++++ *** Dired supports wildcards in the directory part of the file names. +++ diff --git a/lisp/dired.el b/lisp/dired.el index 24759c6c9b..133fd2e719 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2975,6 +2975,14 @@ dired-recursive-deletes ;; Match anything but `.' and `..'. (defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*") +(defconst dired-delete-help + "Type: +`yes' to delete recursively the current directory, +`no' to skip to next, +`!' to delete all remaining directories with no more questions, +`q' to exit, +`help' to show this help message.") + ;; Delete file, possibly delete a directory and all its files. ;; This function is useful outside of dired. One could change its name ;; to e.g. recursive-delete-file and put it somewhere else. @@ -2990,23 +2998,40 @@ dired-delete-file TRASH non-nil means to trash the file instead of deleting, provided `delete-by-moving-to-trash' (which see) is non-nil." - ;; This test is equivalent to - ;; (and (file-directory-p fn) (not (file-symlink-p fn))) - ;; but more efficient - (if (not (eq t (car (file-attributes file)))) - (delete-file file trash) - (if (and recursive - (directory-files file t dired-re-no-dot) ; Not empty. - (or (eq recursive 'always) - (yes-or-no-p (format "Recursively %s %s? " - (if (and trash - delete-by-moving-to-trash) - "trash" - "delete") - (dired-make-relative file))))) - (if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again. - (setq recursive nil)) - (delete-directory file recursive trash))) + ;; This test is equivalent to + ;; (and (file-directory-p fn) (not (file-symlink-p fn))) + ;; but more efficient + (if (not (eq t (car (file-attributes file)))) + (delete-file file trash) + (let* ((valid-answers (list "yes" "no" "!" "q" "help")) + (answer "") + (input-fn (lambda () + (setq answer + (completing-read + (format "Recursively %s %s? [yes, no, !, q, help] " + (if (and trash + delete-by-moving-to-trash) + "trash" + "delete") + (dired-make-relative file)) + valid-answers nil t)) + (when (string= answer "help") + (setq answer "") + (with-help-window "*Help*" + (with-current-buffer "*Help*" (insert dired-delete-help)))) + answer))) + (if (and recursive + (directory-files file t dired-re-no-dot) ; Not empty. + (eq recursive 'always)) + (if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again. + ;; Otherwise prompt user: + (while (string= "" answer) (funcall input-fn)) + (pcase answer + ('"!" (setq recursive 'always dired-recursive-deletes recursive)) + ('"yes" (if (eq recursive 'top) (setq recursive 'always))) + ('"no" (setq recursive nil)) + ('"q" (keyboard-quit)))) + (delete-directory file recursive trash)))) (defun dired-do-flagged-delete (&optional nomessage) "In Dired, delete the files flagged for deletion. @@ -3055,6 +3080,9 @@ dired-internal-do-deletions (let* ((files (mapcar #'car l)) (count (length l)) (succ 0) + ;; Bind `dired-recursive-deletes' so that we can change it + ;; locally according with the user answer within `dired-delete-file'. + (dired-recursive-deletes dired-recursive-deletes) (trashing (and trash delete-by-moving-to-trash))) ;; canonicalize file list for pop up (setq files (nreverse (mapcar #'dired-make-relative files))) @@ -3064,6 +3092,7 @@ dired-internal-do-deletions (if trashing "Trash" "Delete") (dired-mark-prompt arg files))) (save-excursion + (catch '--delete-cancel (let ((progress-reporter (make-progress-reporter (if trashing "Trashing..." "Deleting...") @@ -3081,6 +3110,7 @@ dired-internal-do-deletions (dired-fun-in-all-buffers (file-name-directory fn) (file-name-nondirectory fn) #'dired-delete-entry fn)) + (quit (throw '--delete-cancel (message "OK, canceled"))) (error ;; catch errors from failed deletions (dired-log "%s\n" err) (setq failures (cons (car (car l)) failures))))) @@ -3091,8 +3121,7 @@ dired-internal-do-deletions (format "%d of %d deletion%s failed" (length failures) count (dired-plural-s count)) - failures)))) + failures))))) (message "(No deletions performed)"))) (dired-move-to-filename)) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-08-04 Repository revision: d32d8d0ceaa05939bbf56a246707aed05a53385c