]> code.delx.au - gnu-emacs-elpa/commitdiff
Simplify the ivy-format-function interface
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 27 Feb 2016 07:53:57 +0000 (08:53 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 27 Feb 2016 07:56:26 +0000 (08:56 +0100)
* ivy.el (ivy--format-function-generic): Third arg is no longer a list
  of cons cells, but a list of strings instead.
(ivy-format-function-default):
(ivy-format-function-arrow):
(ivy-format-function-line): Take a string instead of a cons cell.
(ivy--format): Feed strings instead of cons cells to
`ivy-format-function'.

* ivy-test.el (ivy--format): Update test.

* counsel.el (counsel--yank-pop-format-function): Take a string instead
  of a cons cell.

Re #399

counsel.el
ivy-test.el
ivy.el

index fc69a1e0b9775d0eb3efeac1e28ad75599142798..e534601cef8cf28df7b7499b724f06b322ed95b3 100644 (file)
@@ -1465,14 +1465,14 @@ INITIAL-INPUT can be given as the initial minibuffer input."
 
 (defun counsel--yank-pop-format-function (cand-pairs)
   (ivy--format-function-generic
-   (lambda (str _extra)
+   (lambda (str)
      (mapconcat
       (lambda (s)
         (ivy--add-face s 'ivy-current-match))
       (split-string
        (counsel--yank-pop-truncate str) "\n" t)
       "\n"))
-   (lambda (str _extra)
+   (lambda (str)
      (counsel--yank-pop-truncate str))
    cand-pairs
    "\n"))
index e857449e99e2184c79164527c20e08e7763a34e3..7533169396ea122d58326450dd33b52776ab8368 100644 (file)
 
 (ert-deftest ivy--format ()
   (should (string= (let ((ivy--index 10)
-                         (ivy-format-function (lambda (x) (mapconcat (lambda (y) (car y)) x "\n")))
+                         (ivy-format-function (lambda (x) (mapconcat #'identity x "\n")))
                          (cands '("NAME"
                                   "SYNOPSIS"
                                   "DESCRIPTION"
diff --git a/ivy.el b/ivy.el
index bff24547be13a8bb981a259d1b678680e845b4b7..ec51e68a6153148d9a92af1465d07bc7f98d609e 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -2297,49 +2297,47 @@ This string is inserted into the minibuffer."
                                     (- (length str) 3))) "...")
     str))
 
-(defun ivy--format-function-generic (selected-fn other-fn cand-pairs separator)
+(defun ivy--format-function-generic (selected-fn other-fn strs separator)
   "Transform CAND-PAIRS into a string for minibuffer.
 SELECTED-FN and OTHER-FN each take two string arguments.
 SEPARATOR is used to join the candidates."
   (let ((i -1))
     (mapconcat
-     (lambda (pair)
-       (let ((str (car pair))
-             (extra (cdr pair))
-             (curr (eq (cl-incf i) ivy--index)))
+     (lambda (str)
+       (let ((curr (eq (cl-incf i) ivy--index)))
          (if curr
-             (funcall selected-fn str extra)
-           (funcall other-fn str extra))))
-     cand-pairs
+             (funcall selected-fn str)
+           (funcall other-fn str))))
+     strs
      separator)))
 
-(defun ivy-format-function-default (cand-pairs)
+(defun ivy-format-function-default (cands)
   "Transform CAND-PAIRS into a string for minibuffer."
   (ivy--format-function-generic
-   (lambda (str extra)
-     (concat (ivy--add-face str 'ivy-current-match) extra))
-   #'concat
-   cand-pairs
+   (lambda (str)
+     (ivy--add-face str 'ivy-current-match))
+   #'identity
+   cands
    "\n"))
 
-(defun ivy-format-function-arrow (cand-pairs)
+(defun ivy-format-function-arrow (cands)
   "Transform CAND-PAIRS into a string for minibuffer."
   (ivy--format-function-generic
-   (lambda (str extra)
-     (concat "> " (ivy--add-face str 'ivy-current-match) extra))
-   (lambda (str extra)
-     (concat "  " str extra))
-   cand-pairs
+   (lambda (str)
+     (concat "> " (ivy--add-face str 'ivy-current-match)))
+   (lambda (str)
+     (concat "  " str))
+   cands
    "\n"))
 
-(defun ivy-format-function-line (cand-pairs)
+(defun ivy-format-function-line (cands)
   "Transform CAND-PAIRS into a string for minibuffer."
   (ivy--format-function-generic
    (lambda (str extra)
      (ivy--add-face (concat str extra "\n") 'ivy-current-match))
    (lambda (str extra)
      (concat str extra "\n"))
-   cand-pairs
+   cands
    ""))
 
 (defun ivy-add-face-text-property (start end face str)
@@ -2422,8 +2420,8 @@ CANDS is a list of strings."
           (setq cands (mapcar transformer-fn cands))))
       (let* ((ivy--index index)
              (cands (mapcar
-                     (lambda (cand)
-                       (cons (ivy--format-minibuffer-line cand) nil)) cands))
+                     #'ivy--format-minibuffer-line
+                     cands))
              (res (concat "\n" (funcall ivy-format-function cands))))
         (put-text-property 0 (length res) 'read-only nil res)
         res))))