branch: master commit 74bb138e92042f039d1f418ba7829b92b593591b Author: Stephen Whipple <s...@wicdmedia.org> Commit: Oleh Krehel <ohwoeo...@gmail.com>
Update ivy format functions. `ivy-format-function' now accessible via Customize system. `ivy-format-function-default' and `ivy-format-function-arrow' simplified. New format `ivy-format-function-line' added. `counsel-M-x' restores `ivy-format-function' before executing command. Fixes #306 --- counsel.el | 3 ++- ivy.el | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/counsel.el b/counsel.el index 020c917..5354d39 100644 --- a/counsel.el +++ b/counsel.el @@ -887,7 +887,8 @@ Optional INITIAL-INPUT is the initial input in the minibuffer." (lambda (cmd) (when (featurep 'smex) (smex-rank (intern cmd))) - (let ((prefix-arg current-prefix-arg)) + (let ((prefix-arg current-prefix-arg) + (ivy-format-function store)) (command-execute (intern cmd) 'record))) :sort sort :keymap counsel-describe-map diff --git a/ivy.el b/ivy.el index f83d0d0..c365d47 100644 --- a/ivy.el +++ b/ivy.el @@ -1894,9 +1894,13 @@ Prefix matches to NAME are put ahead of the list." (error cands))) -(defvar ivy-format-function 'ivy-format-function-default +(defcustom ivy-format-function 'ivy-format-function-default "Function to transform the list of candidates into a string. -This string will be inserted into the minibuffer.") +This string will be inserted into the minibuffer." + :type '(choice + (const :tag "Default" ivy-format-function-default) + (const :tag "Arrow prefix" ivy-format-function-arrow) + (const :tag "Full line" ivy-format-function-line))) (defun ivy--truncate-string (str width) "Truncate STR to WIDTH." @@ -1907,28 +1911,36 @@ This string will be inserted into the minibuffer.") (defun ivy-format-function-default (cands) "Transform CANDS into a string for minibuffer." - (if (bound-and-true-p truncate-lines) - (mapconcat #'identity cands "\n") - (let ((ww (- (window-width) - (if (and (boundp 'fringe-mode) (eq fringe-mode 0)) 1 0)))) - (mapconcat - (if truncate-lines - (lambda (s) - (ivy--truncate-string s ww)) - #'identity) - cands "\n")))) + (let ((i -1)) + (mapconcat + (lambda (s) + (when (eq (cl-incf i) ivy--index) + (ivy--add-face s 'ivy-current-match)) + s) + cands "\n"))) (defun ivy-format-function-arrow (cands) "Transform CANDS into a string for minibuffer." (let ((i -1)) (mapconcat (lambda (s) - (concat (if (eq (cl-incf i) ivy--index) - "> " - " ") - s)) + (let ((curr (eq (cl-incf i) ivy--index))) + (when curr + (ivy--add-face s 'ivy-current-match)) + (concat (if curr "> " " ") s))) cands "\n"))) +(defun ivy-format-function-line (cands) + "Transform CANDS into a string for minibuffer." + (let ((i -1)) + (mapconcat + (lambda (s) + (let ((line (concat s "\n"))) + (when (eq (cl-incf i) ivy--index) + (ivy--add-face line 'ivy-current-match)) + line)) + cands ""))) + (defface ivy-minibuffer-match-face-1 '((((class color) (background light)) :background "#d3d3d3") @@ -2032,8 +2044,6 @@ CANDS is a list of strings." (setq cands (mapcar #'ivy--format-minibuffer-line cands)) - (setf (nth index cands) - (ivy--add-face (nth index cands) 'ivy-current-match)) (let* ((ivy--index index) (res (concat "\n" (funcall ivy-format-function cands)))) (put-text-property 0 (length res) 'read-only nil res)