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

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

[elpa] master cdafe1b 05/12: Merge ivy--action into ivy-last


From: Oleh Krehel
Subject: [elpa] master cdafe1b 05/12: Merge ivy--action into ivy-last
Date: Sun, 03 May 2015 11:04:52 +0000

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

    Merge ivy--action into ivy-last
    
    * ivy.el (ivy-state): Add action field.
    (ivy-set-action): New defun. Just a shortcut to set action.
    (ivy--action): Remove defvar.
    (ivy-read): Add action argument. Check (ivy-state-action ivy-last) in
    the end and call it, since the action can change during the completion.
    (ivy--insert-prompt): Add `counsel-find-symbol' to the list.
    (ivy--format): If there are no matches, set `ivy--current' to "".
---
 counsel.el |   98 ++++++++++++++++++++++++++---------------------------------
 ivy.el     |   25 ++++++++-------
 swiper.el  |    9 ++---
 3 files changed, 61 insertions(+), 71 deletions(-)

diff --git a/counsel.el b/counsel.el
index 27825fe..daa05b9 100644
--- a/counsel.el
+++ b/counsel.el
@@ -48,9 +48,8 @@
 (defun counsel-find-symbol ()
   "Jump to the definition of the current symbol."
   (interactive)
-  (setq ivy--action 'counsel--find-symbol)
-  (setq ivy-exit 'done)
-  (exit-minibuffer))
+  (ivy-set-action 'counsel--find-symbol)
+  (ivy-done))
 
 (defun counsel--find-symbol ()
   (let ((sym (read ivy--current)))
@@ -69,58 +68,47 @@
 (defvar counsel-describe-symbol-history nil
   "History for `counsel-describe-variable' and `counsel-describe-function'.")
 
-(defun counsel-describe-variable (variable &optional buffer frame)
-  "Forward to (`describe-variable' VARIABLE BUFFER FRAME)."
-  (interactive
-   (let ((v (variable-at-point))
-         (enable-recursive-minibuffers t)
-         (preselect (thing-at-point 'symbol))
-         val)
-     (setq ivy--action nil)
-     (setq val (ivy-read
-                "Describe variable: "
-                (let (cands)
-                  (mapatoms
-                   (lambda (vv)
-                     (when (or (get vv 'variable-documentation)
-                               (and (boundp vv) (not (keywordp vv))))
-                       (push (symbol-name vv) cands))))
-                  cands)
-                :keymap counsel-describe-map
-                :preselect preselect
-                :history 'counsel-describe-symbol-history
-                :require-match t
-                :sort t))
-     (list (if (equal val "")
-               v
-             (intern val)))))
-  (unless (eq ivy--action 'counsel--find-symbol)
-    (describe-variable variable buffer frame)))
+(defun counsel-describe-variable ()
+  "Forward to `describe-variable'."
+  (interactive)
+  (let ((enable-recursive-minibuffers t))
+    (ivy-read
+     "Describe variable: "
+     (let (cands)
+       (mapatoms
+        (lambda (vv)
+          (when (or (get vv 'variable-documentation)
+                    (and (boundp vv) (not (keywordp vv))))
+            (push (symbol-name vv) cands))))
+       cands)
+     :keymap counsel-describe-map
+     :preselect (thing-at-point 'symbol)
+     :history 'counsel-describe-symbol-history
+     :require-match t
+     :sort t
+     :action (lambda ()
+               (describe-variable
+                (intern ivy--current))))))
 
-(defun counsel-describe-function (function)
-  "Forward to (`describe-function' FUNCTION) with ivy completion."
-  (interactive
-   (let ((fn (function-called-at-point))
-         (enable-recursive-minibuffers t)
-         (preselect (thing-at-point 'symbol))
-         val)
-     (setq ivy--action nil)
-     (setq val (ivy-read "Describe function: "
-                         (let (cands)
-                           (mapatoms
-                            (lambda (x)
-                              (when (fboundp x)
-                                (push (symbol-name x) cands))))
-                           cands)
-                         :keymap counsel-describe-map
-                         :preselect preselect
-                         :history 'counsel-describe-symbol-history
-                         :require-match t
-                         :sort t))
-     (list (if (equal val "")
-               fn (intern val)))))
-  (unless (eq ivy--action 'counsel--find-symbol)
-    (describe-function function)))
+(defun counsel-describe-function ()
+  "Forward to `describe-function'."
+  (interactive)
+  (let ((enable-recursive-minibuffers t))
+    (ivy-read "Describe function: "
+              (let (cands)
+                (mapatoms
+                 (lambda (x)
+                   (when (fboundp x)
+                     (push (symbol-name x) cands))))
+                cands)
+              :keymap counsel-describe-map
+              :preselect (thing-at-point 'symbol)
+              :history 'counsel-describe-symbol-history
+              :require-match t
+              :sort t
+              :action (lambda ()
+                        (describe-function
+                         (intern ivy--current))))))
 
 (defvar info-lookup-mode)
 (declare-function info-lookup->completions "info-look")
diff --git a/ivy.el b/ivy.el
index 8ea8334..0e40d68 100644
--- a/ivy.el
+++ b/ivy.el
@@ -123,11 +123,15 @@ Only \"./\" and \"../\" apply here. They appear in 
reverse order."
   predicate require-match initial-input
   history preselect keymap update-fn sort
   ;; The window in which `ivy-read' was called
-  window)
+  window
+  action)
 
 (defvar ivy-last nil
   "The last parameters passed to `ivy-read'.")
 
+(defsubst ivy-set-action (action)
+  (setf (ivy-state-action ivy-last) action))
+
 (defvar ivy-history nil
   "History list of candidates entered in the minibuffer.
 
@@ -153,9 +157,6 @@ of `history-length', which see.")
   "Store 'done if the completion was successfully selected.
 Otherwise, store nil.")
 
-(defvar ivy--action nil
-  "Store a function to call at the end of `ivy--read'.")
-
 (defvar ivy--persistent-action nil
   "Store a function to call for current candidate without exiting.")
 
@@ -514,8 +515,9 @@ Directories come first."
 
 ;;** Entry Point
 (cl-defun ivy-read (prompt collection
-                    &key predicate require-match initial-input
-                      history preselect keymap update-fn sort)
+                           &key predicate require-match initial-input
+                           history preselect keymap update-fn sort
+                           action)
   "Read a string in the minibuffer, with completion.
 
 PROMPT is a string to prompt with; normally it ends in a colon
@@ -547,6 +549,7 @@ When SORT is t, refer to `ivy-sort-functions-alist' for 
sorting."
          :keymap keymap
          :update-fn update-fn
          :sort sort
+         :action action
          :window (selected-window)))
   (setq ivy--directory nil)
   (setq ivy--regex-function
@@ -631,7 +634,6 @@ When SORT is t, refer to `ivy-sort-functions-alist' for 
sorting."
                  prompt)
                 (t
                  nil)))
-    (setq ivy--action nil)
     (prog1
         (unwind-protect
              (minibuffer-with-setup-hook
@@ -649,8 +651,8 @@ When SORT is t, refer to `ivy-sort-functions-alist' for 
sorting."
                                            (cdr (symbol-value hist)))))
                    res)))
           (remove-hook 'post-command-hook #'ivy--exhibit))
-      (when ivy--action
-        (funcall ivy--action)))))
+      (when (setq action (ivy-state-action ivy-last))
+        (funcall action)))))
 
 (defun ivy-completing-read (prompt collection
                             &optional predicate require-match initial-input
@@ -817,7 +819,8 @@ Everything after \"!\" should not match."
 (defun ivy--insert-prompt ()
   "Update the prompt according to `ivy--prompt'."
   (when ivy--prompt
-    (unless (memq this-command '(ivy-done ivy-alt-done ivy-partial-or-done))
+    (unless (memq this-command '(ivy-done ivy-alt-done ivy-partial-or-done
+                                 counsel-find-symbol))
       (setq ivy--prompt-extra ""))
     (let (head tail)
       (if (string-match "\\(.*\\): $" ivy--prompt)
@@ -996,7 +999,7 @@ CANDS is a list of strings."
   (when (>= ivy--index ivy--length)
     (setq ivy--index (max (1- ivy--length) 0)))
   (if (null cands)
-      ""
+      (setq ivy--current "")
     (let* ((half-height (/ ivy-height 2))
            (start (max 0 (- ivy--index half-height)))
            (end (min (+ start (1- ivy-height)) ivy--length))
diff --git a/swiper.el b/swiper.el
index d15ed80..c727289 100644
--- a/swiper.el
+++ b/swiper.el
@@ -88,11 +88,10 @@
            (from (ivy--regex ivy-text))
            (to (query-replace-read-to from "Query replace" t)))
       (delete-minibuffer-contents)
-      (setq ivy--action
-            (lambda ()
-              (with-selected-window swiper--window
-                (perform-replace from to
-                                 t t nil))))
+      (ivy-set-action (lambda ()
+                        (with-selected-window swiper--window
+                          (perform-replace from to
+                                           t t nil))))
       (swiper--cleanup)
       (exit-minibuffer))))
 



reply via email to

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