Function: string-truncate-left
string-truncate-left is an autoloaded and byte-compiled function
defined in subr-x.el.gz.
Signature
(string-truncate-left STRING LENGTH)
Documentation
If STRING is longer than LENGTH, return a truncated version.
When truncating, "..." is always prepended to the string, so
the resulting string may be longer than the original if LENGTH is
3 or smaller.
Other relevant functions are documented in the string group.
Shortdoc
;; string
(string-truncate-left "longstring" 8)
=> "...tring"
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/subr-x.el.gz
;;;###autoload
(defun string-truncate-left (string length)
"If STRING is longer than LENGTH, return a truncated version.
When truncating, \"...\" is always prepended to the string, so
the resulting string may be longer than the original if LENGTH is
3 or smaller."
(declare (pure t) (side-effect-free t))
(let ((strlen (length string)))
(if (<= strlen length)
string
(setq length (max 0 (- length 3)))
(concat "..." (substring string (min (1- strlen)
(max 0 (- strlen length))))))))