Function: which-key--truncate-description

which-key--truncate-description is a byte-compiled function defined in which-key.el.gz.

Signature

(which-key--truncate-description DESC AVL-WIDTH)

Documentation

Truncate DESC description to which-key-max-description-length.

Source Code

;; Defined in /usr/src/emacs/lisp/which-key.el.gz
(defsubst which-key--truncate-description (desc avl-width)
  "Truncate DESC description to `which-key-max-description-length'."
  (let* ((max which-key-max-description-length)
         (max (cl-etypecase max
                (null nil)
                (integer max)
                (float (truncate (* max avl-width)))
                (function (let ((val (funcall max avl-width)))
                            (if (floatp val) (truncate val) val))))))
    (if (and max (> (length desc) max))
        (let ((dots (and (not (equal which-key-ellipsis ""))
                         (which-key--propertize
                          which-key-ellipsis 'face
                          (get-text-property (1- (length desc)) 'face desc)))))
          (if dots
              (concat (substring desc 0 (- max (length dots))) dots)
            (substring desc 0 max)))
      desc)))