emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/helm c88f68de5c 2/2: New function helm-read-answer-dolist-


From: ELPA Syncer
Subject: [nongnu] elpa/helm c88f68de5c 2/2: New function helm-read-answer-dolist-with-action
Date: Sun, 14 Aug 2022 05:58:47 -0400 (EDT)

branch: elpa/helm
commit c88f68de5cfff9925d399fd16e64a5dda31373fe
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>

    New function helm-read-answer-dolist-with-action
    
    Use it in helm-delete-marked-files-async to ask for killing buffers.
---
 helm-files.el |  7 +++----
 helm-lib.el   | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/helm-files.el b/helm-files.el
index a90d651486..0c77da319c 100644
--- a/helm-files.el
+++ b/helm-files.el
@@ -5840,10 +5840,9 @@ directories are always deleted with no warnings."
                                               "*helm delete files*"))
                        (delete-file helm-ff-delete-log-file))
                      (when buffers
-                       (dolist (buf buffers)
-                         (let ((last-nonmenu-event t))
-                           (when (y-or-n-p (format "Kill buffer %s, too? " 
buf))
-                             (kill-buffer buf)))))
+                       (helm-read-answer-dolist-with-action
+                        "Kill buffer `%s', too? "
+                        buffers #'kill-buffer))
                      (run-with-timer
                       0.1 nil
                       (lambda ()
diff --git a/helm-lib.el b/helm-lib.el
index 87c070c202..d8c56ac836 100644
--- a/helm-lib.el
+++ b/helm-lib.el
@@ -1201,6 +1201,35 @@ Example:
           (cl-return str)
         (message "Please answer by %s" (mapconcat 'identity answer-list ", "))
         (sit-for 1)))))
+
+(defun helm-read-answer-dolist-with-action (prompt list action)
+  "Read answer with PROMPT and execute ACTION on each element of LIST.
+
+Argument PROMPT is a format spec string e.g. \"Do this on %s?\"
+which take each elements of LIST as argument, no need to provide
+the help part i.e. [y,n,!,q] it will be already added.
+
+While looping through LIST, ACTION is executed on each elements
+differently depending of answer:
+
+- y  Execute ACTION on element.
+- n  Skip element.
+- !  Don't ask anymore and execute ACTION on remaining elements.
+- q  Skip all remaining elements."
+  (let (dont-ask)
+    (catch 'break
+      (dolist (elm list)
+        (if dont-ask
+            (funcall action elm)
+          (pcase (helm-read-answer
+                  (format (concat prompt "[y,n,!,q]") elm)
+                  '("y" "n" "!" "q"))
+            ("y" (funcall action elm))
+            ("n" (ignore))
+            ("!" (prog1
+                     (funcall action elm)
+                   (setq dont-ask t)))
+            ("q" (throw 'break nil))))))))
 
 ;;; Symbols routines
 ;;
@@ -1904,6 +1933,7 @@ broken."
      ("(\\<\\(helm-acond\\)\\>" 1 font-lock-keyword-face)
      ("(\\<\\(helm-aand\\)\\>" 1 font-lock-keyword-face)
      ("(\\<\\(helm-with-gensyms\\)\\>" 1 font-lock-keyword-face)
+     ("(\\<\\(helm-read-answer-dolist-with-action\\)\\>" 1 
font-lock-keyword-face)
      ("(\\<\\(helm-read-answer\\)\\>" 1 font-lock-keyword-face))))
 
 (provide 'helm-lib)



reply via email to

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