emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 6e39940 2/2: Ask confirmation for all suspicious wi


From: Tino Calancha
Subject: [Emacs-diffs] master 6e39940 2/2: Ask confirmation for all suspicious wildcards
Date: Sun, 2 Jul 2017 09:12:11 -0400 (EDT)

branch: master
commit 6e39940adba7b96dfe520caa52a1b92a1a84a84f
Author: Tino Calancha <address@hidden>
Commit: Tino Calancha <address@hidden>

    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).
---
 lisp/dired-aux.el | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index a57e5db..12a97f8 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."
       (dired-read-shell-command "! on %s: " current-prefix-arg files)
       current-prefix-arg
       files)))
+  (cl-flet ((need-confirm-p
+             (cmd str)
+             (let ((res cmd)
+                   (regexp (regexp-quote str)))
+               ;; Drop all ? and * surrounded by spaces and `?`.
+               (while (and (string-match regexp res)
+                           (dired--star-or-qmark-p res str))
+                 (setq res (replace-match "" t t res 0)))
+               (string-match regexp res))))
   (let* ((on-each (not (dired--star-or-qmark-p command "*" 'keep)))
         (no-subst (not (dired--star-or-qmark-p command "?" 'keep)))
-        (star (string-match-p "\\*" command))
-        (qmark (string-match-p "\\?" command))
+        (star (string-match "\\*" command))
+        (qmark (string-match "\\?" command))
          ;; Get confirmation for wildcards that may have been meant
          ;; to control substitution of a file name or the file name list.
          (ok (cond ((not (or on-each no-subst))
                    (error "You can not combine `*' and `?' substitution 
marks"))
-                  ((and star on-each)
+                  ((need-confirm-p command "*")
                    (y-or-n-p (format-message
                               "Confirm--do you mean to use `*' as a wildcard? 
")))
-                  ((and qmark no-subst)
+                  ((need-confirm-p command "?")
                    (y-or-n-p (format-message
                               "Confirm--do you mean to use `?' as a wildcard? 
")))
                   (t))))
@@ -755,7 +764,7 @@ can be produced by `dired-get-marked-files', for example."
                             nil file-list)
        ;; execute the shell command
        (dired-run-shell-command
-        (dired-shell-stuff-it command file-list nil arg))))))
+        (dired-shell-stuff-it command file-list nil arg)))))))
 
 ;; Might use {,} for bash or csh:
 (defvar dired-mark-prefix ""



reply via email to

[Prev in Thread] Current Thread [Next in Thread]