branch: master
commit 5480079653d6c7ec59af5e7d79b2eda5bfe1c190
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
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."
(ivy-set-actions
'counsel-locate
- '(("xdg-open" counsel-locate-action-extern)
- ("dired" counsel-locate-action-dired)))
+ '(("x" counsel-locate-action-extern "xdg-open")
+ ("d" counsel-locate-action-dired "dired")))
;;;###autoload
(defun counsel-locate ()
@@ -721,8 +721,8 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
:history 'counsel-rhythmbox-history
:action
'(1
- ("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
order."
(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)
map)
@@ -268,6 +269,29 @@ 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'."
+ (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
instead."
(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)
`(1
- ("default" ,action)
+ ("o" ,action "default")
,@extra-actions)
(delete-dups (append action extra-actions))))))
(setq ivy-last
@@ -1519,10 +1543,11 @@ BUFFER may be a string or nil."
(ivy-set-actions
'ivy-switch-buffer
- '(("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."