[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."
(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."
- [elpa] master e9c2538 19/63: counsel.el (counsel-rhythmbox-history): Add, (continued)
- [elpa] master e9c2538 19/63: counsel.el (counsel-rhythmbox-history): Add, Oleh Krehel, 2015/08/21
- [elpa] master 21007c2 17/63: Add counsel-rhythmbox, Oleh Krehel, 2015/08/21
- [elpa] master de2e819 20/63: Allow % in prompt string, Oleh Krehel, 2015/08/21
- [elpa] master 22ee8a6 23/63: swiper.el (swiper-font-lock-ensure): Ignore Man-mode, Oleh Krehel, 2015/08/21
- [elpa] master 8c91662 22/63: ivy.el (ivy-call): Bind to "C-M-m" or "M-RET", Oleh Krehel, 2015/08/21
- [elpa] master 3df2d8e 26/63: ivy-hydra.el: Add featurep for hydra, Oleh Krehel, 2015/08/21
- [elpa] master d289b78 15/63: Add a new interface to customize additional exit points, Oleh Krehel, 2015/08/21
- [elpa] master 1092e2d 24/63: swiper.el: Update avy--goto -> avy-action-goto, Oleh Krehel, 2015/08/21
- [elpa] master adad288 27/63: ivy.el (ivy-call): Add selected-window work-around for M-x, Oleh Krehel, 2015/08/21
- [elpa] master 9ca6f48 30/63: Allow "C-g" to interrupt ivy-dispatching-done, Oleh Krehel, 2015/08/21
- [elpa] master 5480079 28/63: ivy.el (ivy-dispatching-done): New command on "M-o",
Oleh Krehel <=
- [elpa] master 6062903 21/63: ivy.el (ivy-count-format): Improve docstring, Oleh Krehel, 2015/08/21
- [elpa] master e91a4eb 31/63: ivy.el (ivy-dispatching-done): Display the candidate, Oleh Krehel, 2015/08/21
- [elpa] master 3464362 33/63: Add actions for counsel-describe-variable, Oleh Krehel, 2015/08/21
- [elpa] master 31d664a 32/63: ivy.el (ivy-dispatching-done): Add a trailing newline, Oleh Krehel, 2015/08/21
- [elpa] master 107ebff 34/63: Add actions for counsel-describe-function, Oleh Krehel, 2015/08/21
- [elpa] master 2fbcfb9 29/63: ivy.el (ivy--preselect-index): Add matcher to arglist, Oleh Krehel, 2015/08/21
- [elpa] master cb0cf02 35/63: ivy.el (ivy-call): Remove with-selected-window, Oleh Krehel, 2015/08/21
- [elpa] master 08bd5b4 25/63: counsel.el (counsel-variable-list): Add, Oleh Krehel, 2015/08/21
- [elpa] master ae77d93 36/63: counsel.el (counsel-org-tag): Replace org-set-tags, Oleh Krehel, 2015/08/21
- [elpa] master 1e483c5 37/63: Fixup counsel-org-tag, Oleh Krehel, 2015/08/21