]> git.eshelyaron.com Git - emacs.git/commitdiff
Use text properties instead of truncating strings
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 7 Oct 2019 18:11:26 +0000 (20:11 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 7 Oct 2019 18:11:26 +0000 (20:11 +0200)
* 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
lisp/international/mule-util.el

index ade60285883edb31270749de8a774ef0300dc529..66a859f56ced22db2f3b01bc8f0c989ec2e8f93f 100644 (file)
@@ -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))
index 19d6d165cfd3374416de10eb04f9d269e42665b6..a1603e067178e2909f02bd5868f8dc911e6fc42e 100644 (file)
@@ -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)))))
 
 \f
 ;;; Nested alist handler.