aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorTino Calancha2017-07-02 22:09:21 +0900
committerTino Calancha2017-07-02 22:09:21 +0900
commit6e39940adba7b96dfe520caa52a1b92a1a84a84f (patch)
tree8dc1d4ce136badb6aad962a32b5b7cb766198bc5 /lisp
parenta8b71b3dc53883a2dcb3339bf4c7e1232c42d276 (diff)
downloademacs-6e39940adba7b96dfe520caa52a1b92a1a84a84f.tar.gz
emacs-6e39940adba7b96dfe520caa52a1b92a1a84a84f.zip
Ask confirmation for all suspicious wildcards
* lisp/dired-aux.el (dired-do-shell-command): Check that all the wildcards are right. Otherwise, ask for confirmation (Bug#27496).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dired-aux.el19
1 files changed, 14 insertions, 5 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index a57e5db17b7..12a97f8457e 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -731,18 +731,27 @@ can be produced by `dired-get-marked-files', for example."
731 (dired-read-shell-command "! on %s: " current-prefix-arg files) 731 (dired-read-shell-command "! on %s: " current-prefix-arg files)
732 current-prefix-arg 732 current-prefix-arg
733 files))) 733 files)))
734 (cl-flet ((need-confirm-p
735 (cmd str)
736 (let ((res cmd)
737 (regexp (regexp-quote str)))
738 ;; Drop all ? and * surrounded by spaces and `?`.
739 (while (and (string-match regexp res)
740 (dired--star-or-qmark-p res str))
741 (setq res (replace-match "" t t res 0)))
742 (string-match regexp res))))
734 (let* ((on-each (not (dired--star-or-qmark-p command "*" 'keep))) 743 (let* ((on-each (not (dired--star-or-qmark-p command "*" 'keep)))
735 (no-subst (not (dired--star-or-qmark-p command "?" 'keep))) 744 (no-subst (not (dired--star-or-qmark-p command "?" 'keep)))
736 (star (string-match-p "\\*" command)) 745 (star (string-match "\\*" command))
737 (qmark (string-match-p "\\?" command)) 746 (qmark (string-match "\\?" command))
738 ;; Get confirmation for wildcards that may have been meant 747 ;; Get confirmation for wildcards that may have been meant
739 ;; to control substitution of a file name or the file name list. 748 ;; to control substitution of a file name or the file name list.
740 (ok (cond ((not (or on-each no-subst)) 749 (ok (cond ((not (or on-each no-subst))
741 (error "You can not combine `*' and `?' substitution marks")) 750 (error "You can not combine `*' and `?' substitution marks"))
742 ((and star on-each) 751 ((need-confirm-p command "*")
743 (y-or-n-p (format-message 752 (y-or-n-p (format-message
744 "Confirm--do you mean to use `*' as a wildcard? "))) 753 "Confirm--do you mean to use `*' as a wildcard? ")))
745 ((and qmark no-subst) 754 ((need-confirm-p command "?")
746 (y-or-n-p (format-message 755 (y-or-n-p (format-message
747 "Confirm--do you mean to use `?' as a wildcard? "))) 756 "Confirm--do you mean to use `?' as a wildcard? ")))
748 (t)))) 757 (t))))
@@ -755,7 +764,7 @@ can be produced by `dired-get-marked-files', for example."
755 nil file-list) 764 nil file-list)
756 ;; execute the shell command 765 ;; execute the shell command
757 (dired-run-shell-command 766 (dired-run-shell-command
758 (dired-shell-stuff-it command file-list nil arg)))))) 767 (dired-shell-stuff-it command file-list nil arg)))))))
759 768
760;; Might use {,} for bash or csh: 769;; Might use {,} for bash or csh:
761(defvar dired-mark-prefix "" 770(defvar dired-mark-prefix ""