branch: externals/ivy
commit 6c05de85416504095fd879c665697fdea5a24af1
Merge: e642f65f21 11649c3471
Author: Basil L. Contovounesios <[email protected]>
Commit: Basil L. Contovounesios <[email protected]>

    Merge branch 'master' into externals/ivy
---
 ivy-test.el |  2 ++
 ivy.el      | 27 +++++++++++++++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 4af7e9f907..adcfec67d4 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -53,6 +53,8 @@ Intended as :after-while advice for `require'."
 (require 'ivy)
 
 (require 'ert)
+(eval-when-compile
+  (require 'cl-lib))
 
 (setq ivy-last (make-ivy-state))
 
diff --git a/ivy.el b/ivy.el
index 47b3a36529..a6aca7a2af 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4796,25 +4796,32 @@ Otherwise, forward to `ivy-kill-line'."
 
 (ivy-set-actions
  t
- '(("i" ivy--action-insert "insert")
-   ("w" ivy--action-copy "copy")))
+ `(("i" ,#'ivy--action-insert "insert")
+   ("w" ,#'ivy--action-copy "copy")))
 
 (defun ivy--trim-grep-line-number (x)
   (if (string-match ":[0-9]+:" x)
       (substring x (match-end 0))
     x))
 
+(defun ivy--action-cand-to-str (x)
+  "Try to return Ivy action argument X as a string."
+  (let ((x (if (consp x) (car x) x)))
+    (if (symbolp x) (symbol-name x) x)))
+
 (defun ivy--action-insert (x)
-  (insert
-   (if (stringp x)
-       (ivy--trim-grep-line-number x)
-     (car x))))
+  "Insert completion candidate X into current buffer at point."
+  (insert (funcall (if (stringp x)
+                       #'ivy--trim-grep-line-number
+                     #'ivy--action-cand-to-str)
+                   x)))
 
 (defun ivy--action-copy (x)
-  (kill-new
-   (if (stringp x)
-       (ivy--trim-grep-line-number x)
-     (car x))))
+  "Add completion candidate X to the kill ring."
+  (kill-new (funcall (if (stringp x)
+                         #'ivy--trim-grep-line-number
+                       #'ivy--action-cand-to-str)
+                     x)))
 
 (defun ivy--switch-buffer-matcher (regexp candidates)
   "Return REGEXP matching CANDIDATES.

Reply via email to