branch: master
commit 5a99ddab228ab9a9c8142bbae89f2fc8b3742509
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
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"))))