emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 67830e7: Use text properties instead of truncating


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 67830e7: Use text properties instead of truncating strings
Date: Mon, 7 Oct 2019 14:11:43 -0400 (EDT)

branch: master
commit 67830e756911f0c262bb3a447e58b9ff6739a60f
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Use text properties instead of truncating strings
    
    * lisp/emacs-lisp/tabulated-list.el (tabulated-list-put-tag): Use
    this to allow using commands like `C-s' to search for even
    truncated bits.
    
    * lisp/international/mule-util.el (truncate-string-to-width):
    Allow using text properties to truncate strings instead of
    actually truncating strings (bug#17782).
---
 lisp/emacs-lisp/tabulated-list.el |  2 +-
 lisp/international/mule-util.el   | 21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/lisp/emacs-lisp/tabulated-list.el 
b/lisp/emacs-lisp/tabulated-list.el
index ade6028..66a859f 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -544,7 +544,7 @@ Return the column number after insertion."
     (when (and not-last-col
                (> label-width available-space)
                (setq label (truncate-string-to-width
-                            label available-space nil nil t)
+                            label available-space nil nil t t)
                      label-width available-space)))
     (setq label (bidi-string-mark-left-to-right label))
     (when (and right-align (> width label-width))
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el
index 19d6d16..a1603e0 100644
--- a/lisp/international/mule-util.el
+++ b/lisp/international/mule-util.el
@@ -50,7 +50,8 @@ Serves as default value of ELLIPSIS argument to 
`truncate-string-to-width'.")
 
 ;;;###autoload
 (defun truncate-string-to-width (str end-column
-                                    &optional start-column padding ellipsis)
+                                    &optional start-column padding ellipsis
+                                     ellipsis-text-property)
   "Truncate string STR to end at column END-COLUMN.
 The optional 3rd arg START-COLUMN, if non-nil, specifies the starting
 column; that means to return the characters occupying columns
@@ -72,7 +73,11 @@ If ELLIPSIS is non-nil, it should be a string which will 
replace the
 end of STR (including any padding) if it extends beyond END-COLUMN,
 unless the display width of STR is equal to or less than the display
 width of ELLIPSIS.  If it is non-nil and not a string, then ELLIPSIS
-defaults to `truncate-string-ellipsis'."
+defaults to `truncate-string-ellipsis'.
+
+If ELLIPSIS-TEXT-PROPERTY in non-nil, a too-long string will not
+be truncated, but instead the elided parts will be covered by a
+`display' text property showing the ellipsis."
   (or start-column
       (setq start-column 0))
   (when (and ellipsis (not (stringp ellipsis)))
@@ -113,8 +118,16 @@ defaults to `truncate-string-ellipsis'."
                idx last-idx))
        (when (and padding (< column end-column))
          (setq tail-padding (make-string (- end-column column) padding))))
-      (concat head-padding (substring str from-idx idx)
-             tail-padding ellipsis))))
+      (if (and ellipsis-text-property
+               (not (equal ellipsis ""))
+               idx)
+          ;; Use text properties for the ellipsis.
+          (concat head-padding
+                  (substring str from-idx idx)
+                 (propertize (substring str idx) 'display (or ellipsis "")))
+        ;; (Possibly) chop off bits of the string.
+        (concat head-padding (substring str from-idx idx)
+               tail-padding ellipsis)))))
 
 
 ;;; Nested alist handler.



reply via email to

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