[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5ff5139 051/184: ivy.el (ivy-read-action-function): Allow
From: |
Oleh Krehel |
Subject: |
[elpa] master 5ff5139 051/184: ivy.el (ivy-read-action-function): Allow to read actions using Ivy |
Date: |
Wed, 16 Oct 2019 13:14:47 -0400 (EDT) |
branch: master
commit 5ff5139f60de1939228617d7fc5c925fdc0c5ec6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-read-action-function): Allow to read actions using Ivy
Fixes #2176
---
ivy-hydra.el | 2 +-
ivy.el | 62 ++++++++++++++++++++++++++++++++++++++++--------------------
2 files changed, 43 insertions(+), 21 deletions(-)
diff --git a/ivy-hydra.el b/ivy-hydra.el
index c4fa573..1d586ee 100644
--- a/ivy-hydra.el
+++ b/ivy-hydra.el
@@ -124,7 +124,7 @@ _h_ ^+^ _l_ | _d_one ^ ^ | _o_ops | _M_: matcher
%-5s(ivy--matcher-desc)
(cdr actions))
,@extra-actions))))))
-(define-key ivy-minibuffer-map (kbd "M-o") 'ivy-dispatching-done-hydra)
+(setq ivy-read-action-function (lambda (_) (ivy-dispatching-done-hydra)))
(provide 'ivy-hydra)
diff --git a/ivy.el b/ivy.el
index 396d145..f1ffd66 100644
--- a/ivy.el
+++ b/ivy.el
@@ -873,6 +873,13 @@ key (a string), cmd and doc (a string)."
actions
"\n")))
+(defcustom ivy-read-action-function #'ivy-read-action-by-key
+ "Function used to read an action."
+ :type '(radio
+ (function-item ivy-read-action-by-key)
+ (function-item ivy-read-action-ivy)
+ (function-item ivy-read-action-hydra)))
+
(defun ivy-read-action ()
"Change the action to one of the available ones.
@@ -882,26 +889,41 @@ selection, non-nil otherwise."
(let ((actions (ivy-state-action ivy-last)))
(if (not (ivy--actionp actions))
t
- (let* ((hint (funcall ivy-read-action-format-function (cdr actions)))
- (resize-mini-windows t)
- (key "")
- action-idx)
- (while (and (setq action-idx (cl-position-if
- (lambda (x)
- (string-prefix-p key (car x)))
- (cdr actions)))
- (not (string= key (car (nth action-idx (cdr actions))))))
- (setq key (concat key (string (read-key hint)))))
- (ivy-shrink-after-dispatching)
- (cond ((member key '("" ""))
- nil)
- ((null action-idx)
- (message "%s is not bound" key)
- nil)
- (t
- (message "")
- (setcar actions (1+ action-idx))
- (ivy-set-action actions)))))))
+ (funcall ivy-read-action-function actions))))
+
+(defun ivy-read-action-by-key (actions)
+ (let* ((hint (funcall ivy-read-action-format-function (cdr actions)))
+ (resize-mini-windows t)
+ (key "")
+ action-idx)
+ (while (and (setq action-idx (cl-position-if
+ (lambda (x)
+ (string-prefix-p key (car x)))
+ (cdr actions)))
+ (not (string= key (car (nth action-idx (cdr actions))))))
+ (setq key (concat key (string (read-key hint)))))
+ (ivy-shrink-after-dispatching)
+ (cond ((member key '("" ""))
+ nil)
+ ((null action-idx)
+ (message "%s is not bound" key)
+ nil)
+ (t
+ (message "")
+ (setcar actions (1+ action-idx))
+ (ivy-set-action actions)))))
+
+(defun ivy-read-action-ivy (actions)
+ "Select an action from ACTIONS using Ivy."
+ (let ((enable-recursive-minibuffers t))
+ (ivy-read "action: "
+ (cl-mapcar
+ (lambda (a i) (cons (format "[%s] %s" (nth 0 a) (nth 2 a)) i))
+ (cdr actions) (number-sequence 1 (length (cdr actions))))
+ :action (lambda (a)
+ (setcar actions (cdr a))
+ (ivy-set-action actions))
+ :caller 'ivy-read-action-ivy)))
(defun ivy-shrink-after-dispatching ()
"Shrink the window after dispatching when action list is too large."
- [elpa] master fb78c3f 045/184: swiper.el: Run ispell-comments-and-strings, (continued)
- [elpa] master fb78c3f 045/184: swiper.el: Run ispell-comments-and-strings, Oleh Krehel, 2019/10/16
- [elpa] master ae3576a 037/184: swiper.el (swiper-isearch): Fix scroll on RET, Oleh Krehel, 2019/10/16
- [elpa] master c4e0b0b 032/184: ivy-test.el (ivy-read-file-name-make-directory): Add, Oleh Krehel, 2019/10/16
- [elpa] master fdd2178 042/184: ivy.el (ivy--magic-tilde-directory): Use "~~" to move to local home, Oleh Krehel, 2019/10/16
- [elpa] master a9196a2 035/184: counsel.el (counsel-file-jump-args): Is now a list, Oleh Krehel, 2019/10/16
- [elpa] master e58231e 033/184: ivy.el (ivy-immediate-done): Fix for when "C-j" changed cwd, Oleh Krehel, 2019/10/16
- [elpa] master 0132ced 044/184: counsel.el: Run ispell-comments-and-strings, Oleh Krehel, 2019/10/16
- [elpa] master c4842ec 043/184: Fix typo: 'beggining', Oleh Krehel, 2019/10/16
- [elpa] master 28e9416 052/184: ivy.el (ivy--input): Fix for ediff, Oleh Krehel, 2019/10/16
- [elpa] master dd3e1c9 038/184: swiper.el (swiper--maybe-recenter): Refactor, Oleh Krehel, 2019/10/16
- [elpa] master 5ff5139 051/184: ivy.el (ivy-read-action-function): Allow to read actions using Ivy,
Oleh Krehel <=
- [elpa] master e4e0ec4 049/184: counsel.el (counsel--file-name-filter): Return "cat" on empty input, Oleh Krehel, 2019/10/16
- [elpa] master 17d9c70 036/184: counsel.el (counsel--find-return-list): Re-use counsel--call, Oleh Krehel, 2019/10/16
- [elpa] master 44c4bab 057/184: Restore use-ignore setting on ivy-resume, Oleh Krehel, 2019/10/16
- [elpa] master d3e4514 063/184: Remove obsolete aliases older than one year, Oleh Krehel, 2019/10/16
- [elpa] master 0be5b58 067/184: ivy.el (ivy-partial): Don't rely on subr-x, Oleh Krehel, 2019/10/16
- [elpa] master a986e4e 071/184: ivy.el (ivy--yank-handle-case-fold): Add, Oleh Krehel, 2019/10/16
- [elpa] master e41cbec 073/184: ivy.el (ivy-immediate-done): Fix parent dirs for read-directory-name, Oleh Krehel, 2019/10/16
- [elpa] master 3256447 076/184: ivy.el (ivy--partial-cd-for-single-directory): Extract, Oleh Krehel, 2019/10/16
- [elpa] master 03b3f82 075/184: ivy.el (ivy-partial): Use ivy--filter in place of all-completions, Oleh Krehel, 2019/10/16
- [elpa] master daf4683 081/184: ivy.el (ivy--directory-done): Inhibit distracting TRAMP message for /sudo::, Oleh Krehel, 2019/10/16