]> code.delx.au - gnu-emacs-elpa/commitdiff
Update ivy format functions.
authorStephen Whipple <shw@wicdmedia.org>
Wed, 25 Nov 2015 13:56:02 +0000 (06:56 -0700)
committerOleh Krehel <ohwoeowho@gmail.com>
Wed, 25 Nov 2015 14:44:44 +0000 (15:44 +0100)
`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
ivy.el

index 020c9170fa77855bc1ea0bd1612b3d0ab47ea34c..5354d39c5e5e77c34d1bd1382d2b63b4740a0979 100644 (file)
@@ -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 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)