Function: describe-char-eldoc--truncate

describe-char-eldoc--truncate is a byte-compiled function defined in descr-text.el.gz.

Signature

(describe-char-eldoc--truncate NAME WIDTH)

Documentation

Truncate NAME at white spaces such that it is no longer than WIDTH.

Split NAME on white space character and return string with as many leading words of NAME as possible without exceeding WIDTH characters. If NAME consists of white space characters only, return an empty string. Three dots ("...") are appended to returned string if some of the words from NAME have been omitted.

NB: Function may return string longer than WIDTH if name consists of a single word, or it's first word is longer than WIDTH characters.

Source Code

;; Defined in /usr/src/emacs/lisp/descr-text.el.gz
;;; Describe-Char-ElDoc

(defun describe-char-eldoc--truncate (name width)
  "Truncate NAME at white spaces such that it is no longer than WIDTH.

Split NAME on white space character and return string with as
many leading words of NAME as possible without exceeding WIDTH
characters.  If NAME consists of white space characters only,
return an empty string.  Three dots (\"...\") are appended to
returned string if some of the words from NAME have been omitted.

NB: Function may return string longer than WIDTH if name consists
of a single word, or it's first word is longer than WIDTH
characters."
  (let ((words (split-string name)))
    (if words
        (let ((last words))
          (setq width (- width (length (car words))))
          (while (and (cdr last)
                      (<= (+ (length (cadr last)) (if (cddr last) 4 1)) width))
            (setq last (cdr last))
            (setq width (- width (length (car last)) 1)))
          (let ((ellipsis (and (cdr last) "...")))
            (setcdr last nil)
            (concat (mapconcat #'identity words " ") ellipsis)))
      "")))