]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy.el (ivy--truncate-string): New defun
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 14 Nov 2015 15:22:39 +0000 (16:22 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 14 Nov 2015 15:22:39 +0000 (16:22 +0100)
* ivy.el (ivy-format-function-default): Use `ivy--truncate-string'.

ivy.el

diff --git a/ivy.el b/ivy.el
index 7eb3898e86cbcaa1711e92f83033cf2c135af191..bf898366e7d26026d6381e0c86763e6cb029830a 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -1847,6 +1847,13 @@ Prefix matches to NAME are put ahead of the list."
   "Function to transform the list of candidates into a string.
 This string will be inserted into the minibuffer.")
 
+(defun ivy--truncate-string (str width)
+  "Truncate STR to WIDTH."
+  (if (> (string-width str) width)
+      (concat (substring str 0 (min (- width 3)
+                                    (- (length str) 3))) "...")
+    str))
+
 (defun ivy-format-function-default (cands)
   "Transform CANDS into a string for minibuffer."
   (if (bound-and-true-p truncate-lines)
@@ -1856,9 +1863,7 @@ This string will be inserted into the minibuffer.")
       (mapconcat
        (if truncate-lines
            (lambda (s)
-             (if (> (length s) ww)
-                 (concat (substring s 0 (- ww 3)) "...")
-               s))
+             (ivy--truncate-string s ww))
          #'identity)
        cands "\n"))))