]> code.delx.au - gnu-emacs-elpa/blobdiff - ivy.el
Update ivy format functions.
[gnu-emacs-elpa] / ivy.el
diff --git a/ivy.el b/ivy.el
index f83d0d004c7513b6bcb627a57aa8fd681e18972d..c365d4706ac2529b9ca2ea5d137bcecb4c6b783b 100644 (file)
--- 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)