branch: master commit f647bcad6e7504c2ce1bdeee46200facccc9a7a5 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Simplify the ivy-format-function interface * 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 | 4 ++-- ivy-test.el | 2 +- ivy.el | 44 +++++++++++++++++++++----------------------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/counsel.el b/counsel.el index fc69a1e..e534601 100644 --- a/counsel.el +++ b/counsel.el @@ -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")) diff --git a/ivy-test.el b/ivy-test.el index e857449..7533169 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -143,7 +143,7 @@ (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 bff2454..ec51e68 100644 --- 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))))