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

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

[elpa] master 2c57036 263/399: ivy.el (ivy-call): Modify the API for ivy


From: Oleh Krehel
Subject: [elpa] master 2c57036 263/399: ivy.el (ivy-call): Modify the API for ivy-action second arg
Date: Sat, 20 Jul 2019 14:57:36 -0400 (EDT)

branch: master
commit 2c570362714f9eeb803bee1320f147cc8b682311
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy.el (ivy-call): Modify the API for ivy-action second arg
    
    * ivy.el (ivy-call): The second arg in `ivy-action' must be called
      "marked-candidades" in order to be recognized. This is to allow the
      built-in functions such as `find-file-other-window' to be re-used as
      actions. The function in question, `find-file-other-window', already
      has 2 arguments, so it was mistaken for an action with the
      marked-candidates logic.
    (ivy-mark): Document `marked-candidates'.
    
    Re #561
    Fixes #2068
---
 ivy.el | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/ivy.el b/ivy.el
index ce53a9a..9919981 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1330,10 +1330,13 @@ will be called for each element of this list.")
                             (setq ivy-marked-candidates
                                   (mapcar (lambda (s) (substring s l))
                                           ivy-marked-candidates))
-                            (if (> (length (help-function-arglist action)) 1)
-                                (funcall action x ivy-marked-candidates)
-                              (dolist (c ivy-marked-candidates)
-                                (funcall action c))))
+                            (let ((arglist (help-function-arglist action)))
+                              (if (and (> (length arglist) 1)
+                                       (member 'marked-candidates arglist))
+                                  (funcall action x ivy-marked-candidates)
+                                (dolist (c ivy-marked-candidates)
+                                  (let ((default-directory 
(ivy-state-directory ivy-last)))
+                                    (funcall action c))))))
                         (funcall action x))
                    (ivy-recursive-restore))
             (unless (or (eq ivy-exit 'done)
@@ -4578,7 +4581,16 @@ EVENT gives the mouse position."
           (append ivy-marked-candidates (list marked-cand)))))
 
 (defun ivy-mark ()
-  "Mark the selected candidate and move to the next one."
+  "Mark the selected candidate and move to the next one.
+
+In `ivy-call', `ivy-action' will be called in turn for all marked
+candidates.
+
+However, if `ivy-action' has a second (optional) argument called
+`marked-candidates', then `ivy-action' will be called with two
+arguments: the current candidate and the list of all marked
+candidates. This way, `ivy-action' can make decisions based on
+the whole marked list."
   (interactive)
   (unless (ivy--marked-p)
     (ivy--mark (ivy-state-current ivy-last)))



reply via email to

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