]> code.delx.au - gnu-emacs-elpa/commitdiff
Add unwind argument to ivy-read
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 2 May 2015 15:50:17 +0000 (17:50 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 2 May 2015 15:50:17 +0000 (17:50 +0200)
* 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
swiper.el

diff --git a/ivy.el b/ivy.el
index 05509f8de440435a24c2f2ee62f3972b740f3084..667186e5e55c8fc1b5853f8637606baa9f13b344 100644 (file)
--- 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)))))
 
index c7272890728e5dcd4d47772f623c62467b27b13e..d77e96b026309fc645669a098f70323e46fe2ff5 100644 (file)
--- 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)))))