]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy.el (ivy-dispatching-call): Add and bind to "C-M-o"
authorOleh Krehel <ohwoeowho@gmail.com>
Thu, 8 Oct 2015 11:34:54 +0000 (13:34 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Thu, 8 Oct 2015 11:34:54 +0000 (13:34 +0200)
* ivy.el (ivy-minibuffer-map): Update.
(ivy-read-action): New command.
(ivy-dispatching-done): Update.

* ivy-hydra.el (hydra-ivy): Bind `ivy-read-action' to "a".

Re #254

ivy-hydra.el
ivy.el

index 152812b3e808c4ea1cb6be79cc110eab94b81637..84b592d739f2dbbfd8635bae7bee53a2d6483ec9 100644 (file)
@@ -49,7 +49,7 @@
   "
 ^^^^^^          ^Yes^     ^No^     ^Maybe^            ^Action^
 ^^^^^^^^^^^^^^---------------------------------------------------
-^ ^ _k_ ^ ^     _f_ollow  _i_nsert _c_: calling %s(if ivy-calling \"on\" \"off\")   _w_/_s_: %s(ivy-action-name)
+^ ^ _k_ ^ ^     _f_ollow  _i_nsert _c_: calling %s(if ivy-calling \"on\" \"off\")   _w_/_s_/_a_: %s(ivy-action-name)
 _h_ ^+^ _l_     _d_one    _o_ops   _m_: matcher %s(if (eq ivy--regex-function 'ivy--regex-fuzzy) \"fuzzy\" \"ivy\")
 ^ ^ _j_ ^ ^     _g_o      ^ ^      _<_/_>_: shrink/grow _t_runcate: %`truncate-lines
 "
@@ -74,6 +74,7 @@ _h_ ^+^ _l_     _d_one    _o_ops   _m_: matcher %s(if (eq ivy--regex-function 'i
   ("<" ivy-minibuffer-shrink)
   ("w" ivy-prev-action)
   ("s" ivy-next-action)
+  ("a" ivy-read-action)
   ("t" (setq truncate-lines (not truncate-lines))))
 
 (provide 'ivy-hydra)
diff --git a/ivy.el b/ivy.el
index e06c3ddab4b41d21ac7158b087554cba2e794fda..a841a4b2b7317e1e410d230d69bd8292baa5d990 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -157,6 +157,7 @@ Only \"./\" and \"../\" apply here. They appear in reverse order."
     (define-key map (kbd "M-i") 'ivy-insert-current)
     (define-key map (kbd "C-o") 'hydra-ivy/body)
     (define-key map (kbd "M-o") 'ivy-dispatching-done)
+    (define-key map (kbd "C-M-o") 'ivy-dispatching-call)
     (define-key map (kbd "C-k") 'ivy-kill-line)
     (define-key map (kbd "S-SPC") 'ivy-restrict-to-matches)
     (define-key map (kbd "M-w") 'ivy-kill-ring-save)
@@ -302,12 +303,11 @@ When non-nil, it should contain one %d.")
          (insert ivy-text)
          (ivy--exhibit))))
 
-(defun ivy-dispatching-done ()
-  "Select one of the available actions and call `ivy-done'."
+(defun ivy-read-action ()
+  "Change the action to one of the available ones."
   (interactive)
   (let ((actions (ivy-state-action ivy-last)))
-    (if (null (ivy--actionp actions))
-        (ivy-done)
+    (unless (null (ivy--actionp actions))
       (let* ((hint (concat ivy--current
                            "\n"
                            (mapconcat
@@ -321,14 +321,30 @@ When non-nil, it should contain one %d.")
                             "\n")
                            "\n"))
              (key (string (read-key hint)))
-             (action (assoc key (cdr actions))))
+             (action-idx (cl-position-if
+                          (lambda (x) (equal (car x) key))
+                          (cdr actions))))
         (cond ((string= key "\a"))
-              ((null action)
+              ((null action-idx)
                (error "%s is not bound" key))
               (t
                (message "")
-               (ivy-set-action (nth 1 action))
-               (ivy-done)))))))
+               (setcar actions (1+ action-idx))
+               (ivy-set-action actions)))))))
+
+(defun ivy-dispatching-done ()
+  "Select one of the available actions and call `ivy-done'."
+  (interactive)
+  (ivy-read-action)
+  (ivy-done))
+
+(defun ivy-dispatching-call ()
+  "Select one of the available actions and call `ivy-call'."
+  (interactive)
+  (let ((actions (copy-sequence (ivy-state-action ivy-last))))
+    (ivy-read-action)
+    (ivy-call)
+    (ivy-set-action actions)))
 
 (defun ivy-build-tramp-name (x)
   "Reconstruct X into a path.