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

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

[elpa] master 109fb7d 08/12: Add unwind argument to ivy-read


From: Oleh Krehel
Subject: [elpa] master 109fb7d 08/12: Add unwind argument to ivy-read
Date: Sun, 03 May 2015 11:04:54 +0000

branch: master
commit 109fb7decd31f026c21ee5f7f607d3c8ad15c1c1
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Add unwind argument to ivy-read
    
    * ivy.el (ivy-state): Add `unwind' field.
    (ivy-resume): Update.
    (ivy-read): Call the `unwind' argument in the unwind form.
    
    * swiper.el (swiper--ivy): Use `unwind' for `ivy-read'.
---
 ivy.el    |   25 +++++++++++++++++--------
 swiper.el |    4 ++--
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/ivy.el b/ivy.el
index 05509f8..667186e 100644
--- a/ivy.el
+++ b/ivy.el
@@ -124,7 +124,8 @@ Only \"./\" and \"../\" apply here. They appear in reverse 
order."
   history preselect keymap update-fn sort
   ;; The window in which `ivy-read' was called
   window
-  action)
+  action
+  unwind)
 
 (defvar ivy-last nil
   "The last parameters passed to `ivy-read'.")
@@ -310,7 +311,8 @@ candidate."
    :keymap (ivy-state-keymap ivy-last)
    :update-fn (ivy-state-update-fn ivy-last)
    :sort (ivy-state-sort ivy-last)
-   :action (ivy-state-action ivy-last)))
+   :action (ivy-state-action ivy-last)
+   :unwind (ivy-state-unwind ivy-last)))
 
 (defun ivy-beginning-of-buffer ()
   "Select the first completion candidate."
@@ -511,9 +513,9 @@ Directories come first."
 
 ;;** Entry Point
 (cl-defun ivy-read (prompt collection
-                           &key predicate require-match initial-input
-                           history preselect keymap update-fn sort
-                           action)
+                    &key predicate require-match initial-input
+                      history preselect keymap update-fn sort
+                      action unwind)
   "Read a string in the minibuffer, with completion.
 
 PROMPT is a string to prompt with; normally it ends in a colon
@@ -532,7 +534,11 @@ the ones that match INITIAL-INPUT.
 
 UPDATE-FN is called each time the current candidate(s) is changed.
 
-When SORT is t, refer to `ivy-sort-functions-alist' for sorting."
+When SORT is t, refer to `ivy-sort-functions-alist' for sorting.
+
+ACTION is a lambda to call after a result was selected.
+
+UNWIND is a lambda to call before exiting."
   (setq ivy-last
         (make-ivy-state
          :prompt prompt
@@ -546,7 +552,8 @@ When SORT is t, refer to `ivy-sort-functions-alist' for 
sorting."
          :update-fn update-fn
          :sort sort
          :action action
-         :window (selected-window)))
+         :window (selected-window)
+         :unwind unwind))
   (setq ivy--directory nil)
   (setq ivy--regex-function
         (or (and (functionp collection)
@@ -646,7 +653,9 @@ When SORT is t, refer to `ivy-sort-functions-alist' for 
sorting."
                                    (delete ivy-text
                                            (cdr (symbol-value hist)))))
                    res)))
-          (remove-hook 'post-command-hook #'ivy--exhibit))
+          (remove-hook 'post-command-hook #'ivy--exhibit)
+          (when (setq unwind (ivy-state-unwind ivy-last))
+            (funcall unwind)))
       (when (setq action (ivy-state-action ivy-last))
         (funcall action)))))
 
diff --git a/swiper.el b/swiper.el
index c727289..d77e96b 100644
--- a/swiper.el
+++ b/swiper.el
@@ -195,8 +195,8 @@ Please remove it and update the \"swiper\" package."))
                     :keymap swiper-map
                     :preselect preselect
                     :require-match t
-                    :update-fn #'swiper--update-input-ivy))
-      (swiper--cleanup)
+                    :update-fn #'swiper--update-input-ivy
+                    :unwind #'swiper--cleanup))
       (if (null ivy-exit)
           (goto-char swiper--opoint)
         (swiper--action res ivy-text)))))



reply via email to

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