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'.")
: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."
;;** 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
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
: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)
(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)))))