branch: master
commit 02429f5ffa5a045b03c0b83fe1b6accb32a66d17
Author: Basil L. Contovounesios <[email protected]>
Commit: Oleh Krehel <[email protected]>

    Simplify string padding and truncation
    
    * ivy.el (ivy--truncate-string): Delegate to
      truncate-string-to-width.
    * ivy-overlay.el (ivy-left-pad): Use ivy--truncate-string.
    
    Fixes #1329
---
 ivy-overlay.el | 16 ++++++----------
 ivy.el         |  5 +----
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/ivy-overlay.el b/ivy-overlay.el
index 3e07c24..a4f8983 100644
--- a/ivy-overlay.el
+++ b/ivy-overlay.el
@@ -36,21 +36,17 @@
 (defvar ivy-overlay-at nil
   "Overlay variable for `ivy-display-function-overlay'.")
 
+(declare-function ivy--truncate-string "ivy")
+
 (defun ivy-left-pad (str width)
-  "Pad STR from left with WIDTH spaces."
-  (let ((padding (make-string width ?\ )))
+  "Return STR, but with each line indented by WIDTH spaces.
+Lines are truncated to the window width."
+  (let ((padding (make-string width ?\s)))
     (mapconcat (lambda (x)
-                 (setq x (concat padding x))
-                 (if (> (length x) (window-width))
-                     (concat
-                      (substring x 0 (- (window-width) 4))
-                      "...")
-                   x))
+                 (ivy--truncate-string (concat padding x) (1- (window-width))))
                (split-string str "\n")
                "\n")))
 
-(declare-function company-abort "ext:company")
-
 (defun ivy-overlay-cleanup ()
   "Clean up after `ivy-display-function-overlay'."
   (when (overlayp ivy-overlay-at)
diff --git a/ivy.el b/ivy.el
index 9f214fd..7ee1d00 100644
--- a/ivy.el
+++ b/ivy.el
@@ -3127,10 +3127,7 @@ no sorting is done.")
 
 (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))
+  (truncate-string-to-width str width nil nil t))
 
 (defun ivy--format-function-generic (selected-fn other-fn cands separator)
   "Transform candidates into a string for minibuffer.

Reply via email to