summaryrefslogtreecommitdiff
path: root/lisp/international
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-10-07 20:11:26 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-10-07 20:11:26 +0200
commit67830e756911f0c262bb3a447e58b9ff6739a60f (patch)
tree2e2bf93c156831d8683d37d7c4d641631b5af1fb /lisp/international
parent7b3932f2440df61acd20743f230b05ffc4f8d2d8 (diff)
downloademacs-67830e756911f0c262bb3a447e58b9ff6739a60f.tar.gz
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).
Diffstat (limited to 'lisp/international')
-rw-r--r--lisp/international/mule-util.el21
1 files changed, 17 insertions, 4 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el
index 19d6d165cfd..a1603e06717 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.