emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 5a99dda 118/167: ivy.el (ivy--truncate-string): New defun


From: Oleh Krehel
Subject: [elpa] master 5a99dda 118/167: ivy.el (ivy--truncate-string): New defun
Date: Tue, 08 Dec 2015 10:50:25 +0000

branch: master
commit 5a99ddab228ab9a9c8142bbae89f2fc8b3742509
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy.el (ivy--truncate-string): New defun
    
    * ivy.el (ivy-format-function-default): Use `ivy--truncate-string'.
---
 ivy.el |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/ivy.el b/ivy.el
index 7eb3898..bf89836 100644
--- 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"))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]