[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c6977eb 266/399: ivy.el (ivy-read): Add :multi-action arg
From: |
Oleh Krehel |
Subject: |
[elpa] master c6977eb 266/399: ivy.el (ivy-read): Add :multi-action arg |
Date: |
Sat, 20 Jul 2019 14:57:37 -0400 (EDT) |
branch: master
commit c6977ebc003dd5773c06d559f39afbb62d4be861
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-read): Add :multi-action arg
Re #2068
Re #561
Example:
(defun test ()
(interactive)
(ivy-read "test:" '("a" "b" "c")
:action
(lambda (x) (insert ":" x ":\n"))
:multi-action
(lambda (lst)
(insert (mapconcat #'identity lst ":") "\n"))))
---
ivy.el | 40 +++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/ivy.el b/ivy.el
index 9919981..8adafd2 100644
--- a/ivy.el
+++ b/ivy.el
@@ -450,7 +450,8 @@ action functions.")
directory
caller
current
- def)
+ def
+ multi-action)
(defvar ivy-last (make-ivy-state)
"The last parameters passed to `ivy-read'.
@@ -1326,17 +1327,17 @@ will be called for each element of this list.")
(set-buffer (ivy-state-buffer ivy-last))
(prog1 (unwind-protect
(if ivy-marked-candidates
- (let ((l (length ivy-mark-prefix)))
+ (let ((prefix-len (length ivy-mark-prefix)))
(setq ivy-marked-candidates
- (mapcar (lambda (s) (substring s l))
+ (mapcar (lambda (s) (substring s prefix-len))
ivy-marked-candidates))
- (let ((arglist (help-function-arglist action)))
- (if (and (> (length arglist) 1)
- (member 'marked-candidates arglist))
- (funcall action x ivy-marked-candidates)
- (dolist (c ivy-marked-candidates)
- (let ((default-directory
(ivy-state-directory ivy-last)))
- (funcall action c))))))
+ (if (ivy-state-multi-action ivy-last)
+ (funcall
+ (ivy-state-multi-action ivy-last)
+ ivy-marked-candidates)
+ (dolist (c ivy-marked-candidates)
+ (let ((default-directory (ivy-state-directory
ivy-last)))
+ (funcall action c)))))
(funcall action x))
(ivy-recursive-restore))
(unless (or (eq ivy-exit 'done)
@@ -1801,7 +1802,8 @@ found, it falls back to the key t."
&key
predicate require-match initial-input
history preselect def keymap update-fn sort
- action unwind re-builder matcher
+ action multi-action
+ unwind re-builder matcher
dynamic-collection caller)
"Read a string in the minibuffer, with completion.
@@ -1843,6 +1845,11 @@ to sort candidates before displaying them.
ACTION is a function to call after selecting a candidate.
It takes the candidate, which is a string, as its only argument.
+MULTI-ACTION, when non-nil, is called instead of ACTION when
+there are marked candidates. It takes the list of candidates as
+its only argument. When it's nil, ACTION is called on each marked
+candidate.
+
UNWIND is a function of no arguments to call before exiting.
RE-BUILDER is a function transforming input text into a regex
@@ -1921,6 +1928,7 @@ customizations apply to the current completion session."
update-fn)
:sort sort
:action action
+ :multi-action multi-action
:frame (selected-frame)
:window (selected-window)
:buffer (current-buffer)
@@ -4583,14 +4591,12 @@ EVENT gives the mouse position."
(defun ivy-mark ()
"Mark the selected candidate and move to the next one.
-In `ivy-call', `ivy-action' will be called in turn for all marked
+In `ivy-call', :action will be called in turn for all marked
candidates.
-However, if `ivy-action' has a second (optional) argument called
-`marked-candidates', then `ivy-action' will be called with two
-arguments: the current candidate and the list of all marked
-candidates. This way, `ivy-action' can make decisions based on
-the whole marked list."
+However, if :multi-action was supplied to `ivy-read', then it
+will be called with `ivy-marked-candidates'. This way, it can
+make decisions based on the whole marked list."
(interactive)
(unless (ivy--marked-p)
(ivy--mark (ivy-state-current ivy-last)))
- [elpa] master f628441 259/399: swiper.el (swiper-isearch): Fix "C-r", (continued)
- [elpa] master f628441 259/399: swiper.el (swiper-isearch): Fix "C-r", Oleh Krehel, 2019/07/20
- [elpa] master 743163c 260/399: counsel.el (counsel-minor-history): New history variable, Oleh Krehel, 2019/07/20
- [elpa] master cbb3ee1 262/399: counsel.el (counsel-company): Don't rely on company-point, Oleh Krehel, 2019/07/20
- [elpa] master 77a5ffc 261/399: counsel.el (counsel-package-history): New history variable, Oleh Krehel, 2019/07/20
- [elpa] master d5c9673 265/399: swiper.el (swiper--isearch-format): Fix permanent face modifications, Oleh Krehel, 2019/07/20
- [elpa] master 2c57036 263/399: ivy.el (ivy-call): Modify the API for ivy-action second arg, Oleh Krehel, 2019/07/20
- [elpa] master bea44b7 264/399: counsel.el: Fix compiler warnings, Oleh Krehel, 2019/07/20
- [elpa] master a2af29b 271/399: ivy.el (ivy--occur-insert-lines): Fix missing line numbers, Oleh Krehel, 2019/07/20
- [elpa] master 9a9e3e4 251/399: ivy-test.el (swiper--isearch-format): Add test, Oleh Krehel, 2019/07/20
- [elpa] master 76ef143 258/399: swiper.el (swiper-isearch): Fix ivy-occur, Oleh Krehel, 2019/07/20
- [elpa] master c6977eb 266/399: ivy.el (ivy-read): Add :multi-action arg,
Oleh Krehel <=
- [elpa] master df0d980 267/399: Modify counsel-unicode-char's copy action to use actual result, Oleh Krehel, 2019/07/20
- [elpa] master 19ff7cf 270/399: counsel.el (counsel-register-action): Tweak error, Oleh Krehel, 2019/07/20
- [elpa] master 4898a5e 272/399: counsel.el (counsel-compile): better handling for counsel--get-build-subdirs, Oleh Krehel, 2019/07/20
- [elpa] master e95a16b 275/399: Shrink ivy window after read action., Oleh Krehel, 2019/07/20
- [elpa] master 226171b 268/399: ivy.el (ivy--occur-insert-lines): Don't highlight the file name part, Oleh Krehel, 2019/07/20
- [elpa] master e8f9370 273/399: counsel.el (counsel-compile): nreverse recent history, Oleh Krehel, 2019/07/20
- [elpa] master b65cdb5 274/399: counsel.el (counsel-compile): track build dir for the benefit of M-i, Oleh Krehel, 2019/07/20
- [elpa] master a18de2f 269/399: counsel.el (counsel-register): Add, Oleh Krehel, 2019/07/20
- [elpa] master fbf654c 276/399: counsel.el (counsel-company): Rely on company-prefix if company-common is nil, Oleh Krehel, 2019/07/20
- [elpa] master 2410219 284/399: swiper.el (swiper-isearch-highlight-delay): New defcustom, Oleh Krehel, 2019/07/20