[Top][All Lists]

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

[elpa] master 5480079 28/63: ivy.el (ivy-dispatching-done): New command

From: Oleh Krehel
Subject: [elpa] master 5480079 28/63: ivy.el (ivy-dispatching-done): New command on "M-o"
Date: Fri, 21 Aug 2015 12:08:38 +0000

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

    ivy.el (ivy-dispatching-done): New command on "M-o"
    * ivy.el (ivy-minibuffer-map): Bind "M-o" to `ivy-dispatching-done'.
    (ivy-action-name): Update, all actions are now in hydra's format - key
    binding, command, hint.
    (ivy-read): The default action is bound to "o" in the dispatch.
    (ivy-switch-buffer): Update to new action format.
    * counsel.el (counsel-locate):
    (counsel-rhythmbox): Update to new action format.
    The new interface allows to do whatever you want with the selected
    candidate with a very short key binding.
    The old interface with "C-o w/s" still works, but:
    - it gives a lot more info than necessary for only selecting action
    - doesn't scale well with the number of actions: for 10 actions you
      would cycle "w/s" a lot.
    Example with `ivy-switch-buffer':
    - switch to selected buffer: "C-m"
    - kill selected buffer: "M-o k"; you get a hint right after "M-o".
    When there is only one action, "M-o" will forward to "C-m".
 counsel.el |    8 ++++----
 ivy.el     |   33 +++++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/counsel.el b/counsel.el
index bbb8230..7d39f9a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -453,8 +453,8 @@ Skip some dotfiles unless `ivy-text' requires them."
- '(("xdg-open" counsel-locate-action-extern)
-   ("dired" counsel-locate-action-dired)))
+ '(("x" counsel-locate-action-extern "xdg-open")
+   ("d" counsel-locate-action-dired "dired")))
 (defun counsel-locate ()
@@ -721,8 +721,8 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
             :history 'counsel-rhythmbox-history
-              ("Play song" helm-rhythmbox-play-song)
-              ("Enqueue song" counsel-rhythmbox-enqueue-song))))
+              ("p" helm-rhythmbox-play-song "Play song")
+              ("e" counsel-rhythmbox-enqueue-song "Enqueue song"))))
 (provide 'counsel)
diff --git a/ivy.el b/ivy.el
index 8237704..bc26b6f 100644
--- a/ivy.el
+++ b/ivy.el
@@ -135,6 +135,7 @@ Only \"./\" and \"../\" apply here. They appear in reverse 
     (define-key map (kbd "M-j") 'ivy-yank-word)
     (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-k") 'ivy-kill-line)
     (define-key map (kbd "S-SPC") 'ivy-restrict-to-matches)
@@ -268,6 +269,29 @@ When non-nil, it should contain one %d.")
          (insert ivy-text)
+(defun ivy-dispatching-done ()
+  "Select one of the available actions and call `ivy-done'."
+  (interactive)
+  (let ((actions (ivy-state-action ivy-last)))
+    (if (null (ivy--actionp actions))
+        (ivy-done)
+      (let* ((hint (mapconcat
+                    (lambda (x)
+                      (format "%s: %s"
+                              (propertize
+                               (car x)
+                               'face 'font-lock-builtin-face)
+                              (nth 2 x)))
+                    (cdr actions)
+                    "\n"))
+             (key (string (read-key hint)))
+             (action (assoc key (cdr actions))))
+        (if (null action)
+            (error "%s is not bound" key)
+          (message "")
+          (ivy-set-action (nth 1 action))
+          (ivy-done))))))
 (defun ivy-build-tramp-name (x)
   "Reconstruct X into a path.
 Is is a cons cell, related to `tramp-get-completion-function'."
@@ -537,7 +561,7 @@ If the input is empty, select the previous history element 
         (format "[%d/%d] %s"
                 (car action)
                 (1- (length action))
-                (car (nth (car action) action)))
+                (nth 2 (nth (car action) action)))
       "[1/1] default")))
 (defun ivy-call ()
@@ -808,7 +832,7 @@ candidates with each input."
       (setq action
             (if (functionp action)
-                  ("default" ,action)
+                  ("o" ,action "default")
               (delete-dups (append action extra-actions))))))
   (setq ivy-last
@@ -1519,10 +1543,11 @@ BUFFER may be a string or nil."
- '(("kill"
+ '(("k"
     (lambda (x)
       (kill-buffer x)
-      (ivy--reset-state ivy-last)))))
+      (ivy--reset-state ivy-last))
+    "kill")))
 (defun ivy-switch-buffer ()
   "Switch to another buffer."

reply via email to

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