From e7aabd8b1ced130c8bf5abecf2fa14b962a9b012 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sun, 6 Aug 2017 21:53:07 +0900 Subject: [PATCH] dired-delete-file: Do not TAB complete the user answer This action might delete directories containing valuable information. Before previous commit, we prompted users with `yes-or-no-p' which doesn't TAB complete the user answer. Let's play safe and keep requiring full answers. * emacs-master/lisp/dired.el (dired-delete-file): Use `read-string' instead of `completing-read' to read the user answers. --- lisp/dired.el | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lisp/dired.el b/lisp/dired.el index 0bad2562eb4..54bc6217031 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -3011,27 +3011,32 @@ TRASH non-nil means to trash the file instead of deleting, provided (delete-file file trash) (let* ((valid-answers (list "yes" "no" "all" "quit" "help")) (answer "") - (input-fn (lambda () - (setq answer - (completing-read - (format "Recursively %s %s? [yes, no, all, quit, 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))) + (input-fn + (lambda () + (setq answer + (read-string + (format "Recursively %s %s? [yes, no, all, quit, help] " + (if (and trash + delete-by-moving-to-trash) + "trash" + "delete") + (dired-make-relative file)))) + (when (string= answer "help") + (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)) + (funcall input-fn) + (while (not (member answer valid-answers)) + (unless (string= answer "help") + (beep) + (message "Please answer `yes' or `no' or `all' or `quit'") + (sleep-for 2)) + (funcall input-fn)) (pcase answer ('"all" (setq recursive 'always dired-recursive-deletes recursive)) ('"yes" (if (eq recursive 'top) (setq recursive 'always))) -- 2.39.5