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 18:29:41 +0900 Message-ID: <87vam365q2.fsf@calancha-pc> References: <87o9rwxmfz.fsf@jidanni.org> <87r2wrkacy.fsf@calancha-pc> <83a83fybrc.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1501839018 23702 195.159.176.226 (4 Aug 2017 09:30:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Aug 2017 09:30:18 +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 11:30:12 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 1ddYvr-0005oA-JS for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 11:30:11 +0200 Original-Received: from localhost ([::1]:50302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddYvx-0005cs-P4 for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Aug 2017 05:30:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddYvn-0005U8-BN for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 05:30:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddYvi-0000sM-Pw for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 05:30:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ddYvi-0000sI-Ll for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 05:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ddYvi-0001cP-DM for bug-gnu-emacs@gnu.org; Fri, 04 Aug 2017 05:30: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 09:30: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.15018389936183 (code B ref 27940); Fri, 04 Aug 2017 09:30:02 +0000 Original-Received: (at 27940) by debbugs.gnu.org; 4 Aug 2017 09:29:53 +0000 Original-Received: from localhost ([127.0.0.1]:40887 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddYvZ-0001bf-Ct for submit@debbugs.gnu.org; Fri, 04 Aug 2017 05:29:53 -0400 Original-Received: from mail-pg0-f54.google.com ([74.125.83.54]:38493) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ddYvX-0001bS-8D for 27940@debbugs.gnu.org; Fri, 04 Aug 2017 05:29:51 -0400 Original-Received: by mail-pg0-f54.google.com with SMTP id l64so5770503pge.5 for <27940@debbugs.gnu.org>; Fri, 04 Aug 2017 02:29:51 -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=MMPiAffJGkOHJ5wxCsyNmlF9yGcYQ2a0338WyaKIzvw=; b=fTb/fmy09sWwQkwqMWTtAf2zIzUVUscqsGH8ICG6DLK2F6Cvg5Gg33e7dFzNWtRYSG iv7mqA1i+qFZzQpeQh0GFIpSyTyCGiqtYdxmpV/i95J6aqw63IUcp8rN5mm4agoE7Uwz yGPYIGc4qigE0RIBONJNd8ZlMrJZlKE4K2l/Tl1a05mrxGbWcVQ9XtQ785Zv97o+CVkQ /TZUrGVLHFLf8NpkCEpy0LM7ypGfNTJISaM5A2ceB+xjyGB4DTxs15EB8HZuVM7z8FMR 5RTGBLe7fxu/JdFyJxXFvtyejZnmcutNGxq8RuDpScQjWZBVU5ZoE0KKAWRzEioN+jGN SeqA== 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=MMPiAffJGkOHJ5wxCsyNmlF9yGcYQ2a0338WyaKIzvw=; b=WlNpe5x45cmbhsEBIV7fTvjIdI5VdCsFJwCjfxaJvBLJP/shggfTwjzwzj8B/9bnLv W4+g+zYnSQ09MKt4wZvJjGjgYbZwNqYKU3f+IQo7r+WiKpC/VdyIcGdQfHRq/lO4YINF 9l2ul6ezLE25XT41wsdCy0GLDX1kx4M2ZZM3Mle+FPpNTMoxamEZhBg+nSB8HYlfnliV PETjXq+iOE6rNR4NTkpnIu0ECaC3dIR3o3qzn5gNjPlwH51KF9ac90ugFquDjDy6U6kd NC4flnR5rrLFPKvavSFtp7qBWuzYifsIBDmtW2iSbWr5BiC7mgWWoACr9rVOZ+CmMsED ZF2g== X-Gm-Message-State: AIVw1139X0qPXZQEEOgn9Wqnwb/EQrq69t30S7L5216vVvAFo5Fr6jm7 SAhBSrQ/fH1t8Q== X-Received: by 10.84.215.205 with SMTP id g13mr2045183plj.8.1501838985127; Fri, 04 Aug 2017 02:29:45 -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 t8sm1682586pgq.68.2017.08.04.02.29.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Aug 2017 02:29:44 -0700 (PDT) In-Reply-To: <83a83fybrc.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 04 Aug 2017 11:31:51 +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:135332 Archived-At: Eli Zaretskii writes: >> From: Tino Calancha >> Cc: 27940@debbugs.gnu.org, Eli Zaretskii >> Date: Fri, 04 Aug 2017 17:25:49 +0900 >> >> > dired-do-flagged-delete and me interaction: >> > Recursively delete dcepc? (yes or no) yes >> > Recursively delete emmpc? (yes or no) yes >> > Recursively delete zpspc? (yes or no) yes >> > Recursively delete dgcpc? (yes or no) yes >> > >> > Wouldn't it be nice if there was instead: >> > Recursively delete dgcpc? (yes, no, all, quit) >> > >> > Yes, if before we started we set the variables we needn't be asked all >> > those questions. >> > >> > But now *midway* through the list, we decide we would like no more >> > question, there should be a way, without needing to quit and start over, >> > even if doing that isn't so bad. >> Thanks for the suggestion. >> You can already quit with '\C-g'. >> Concerning accept 'all' in the prompt, i am not sure: >> it's a bit dangerous operation. >> >> In the other hand: >> 1) Customize `dired-recursive-deletes' to value 'always. >> 2) Do the deletion. >> 3) Set back `dired-recursive-deletes' to its original value. > > Actually, I think the value he wants is 'top'. The he would be prompted the 34 times all over. I think the OP wants 'always (like Bon Jovi). > I don't object to accepting something like "!" to mean "all", I > believe we already have a few features that do this, and the > implementation should be simple, I think. (Creeping featurism, I > know, but what else did you expect from users who have no real bugs to > report? ;-) > >> How about if `dired-do-delete' called interactively with 2 prefices >> performs recursive deletions? >> Eli? > > Sounds too cumbersome to me. Updated patch. Now it accepts answers: y, n, !, q (as the OP suggested) --8<-----------------------------cut here---------------start------------->8--- commit 90e4eb9fa1b708bab87844160371ec9ce439ab91 Author: Tino Calancha Date: Fri Aug 4 18:17:51 2017 +0900 dired-do-delete: Allow to delete dirs recursively * lisp/dired.el (dired-delete-file): Accept 2 additional answers: '!', to delete all directories recursively and no prompt anymore. 'q', to cancel the directry deletions (Bug#27940). (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. diff --git a/lisp/dired.el b/lisp/dired.el index 24759c6c9b..278acc2cf5 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2990,23 +2990,33 @@ 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 "y" "n" "!" "q")) + (answer "") + (input-fn (lambda () + (setq answer + (completing-read (format "Recursively %s %s? [y, n, !, q] " + (if (and trash + delete-by-moving-to-trash) + "trash" + "delete") + (dired-make-relative file)) + valid-answers nil t))))) + (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)) + ('"y" (if (eq recursive 'top) (setq recursive 'always))) + ('"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 +3065,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 +3077,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 +3095,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,7 +3106,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: db5d38ddb0de83d8f920b7a128fe3fd5156fdf85