Function: describe-char-eldoc--format
describe-char-eldoc--format is a byte-compiled function defined in
descr-text.el.gz.
Signature
(describe-char-eldoc--format CH &optional WIDTH)
Documentation
Format a description for character CH which is no more than WIDTH characters.
Full description message has a "U+HEX: NAME (GC: GENERAL-CATEGORY)"
format where:
- HEX is a hexadecimal codepoint of the character (zero-padded to at
least four digits),
- NAME is name of the character.
- GC is a two-letter abbreviation of the general-category of the
character, and
- GENERAL-CATEGORY is full name of the general-category of the
character.
If WIDTH is non-nil some elements of the description may be
omitted to accommodate the length restriction. Under certain
condition, the function may return string longer than WIDTH, see
describe-char-eldoc--truncate.
Source Code
;; Defined in /usr/src/emacs/lisp/descr-text.el.gz
(defun describe-char-eldoc--format (ch &optional width)
"Format a description for character CH which is no more than WIDTH characters.
Full description message has a \"U+HEX: NAME (GC: GENERAL-CATEGORY)\"
format where:
- HEX is a hexadecimal codepoint of the character (zero-padded to at
least four digits),
- NAME is name of the character.
- GC is a two-letter abbreviation of the general-category of the
character, and
- GENERAL-CATEGORY is full name of the general-category of the
character.
If WIDTH is non-nil some elements of the description may be
omitted to accommodate the length restriction. Under certain
condition, the function may return string longer than WIDTH, see
`describe-char-eldoc--truncate'."
(let ((name (get-char-code-property ch 'name)))
(when name
(let* ((code (propertize (format "U+%04X" ch)
'face 'font-lock-constant-face))
(gc (get-char-code-property ch 'general-category))
(gc-desc (char-code-property-description 'general-category gc)))
(unless (or (not width) (<= (length name) width))
(setq name (describe-char-eldoc--truncate name width)))
(setq name (concat (substring name 0 1) (downcase (substring name 1))))
(setq name (propertize name 'face 'font-lock-variable-name-face))
(setq gc (propertize (symbol-name gc) 'face 'font-lock-comment-face))
(when gc-desc
(setq gc-desc (propertize gc-desc 'face 'font-lock-comment-face)))
(let ((lcode (length code))
(lname (length name))
(lgc (length gc))
(lgc-desc (and gc-desc (length gc-desc))))
(cond
((and gc-desc
(or (not width) (<= (+ lcode lname lgc lgc-desc 7) width)))
(concat code ": " name " (" gc ": " gc-desc ")"))
((and gc-desc (<= (+ lcode lname lgc-desc 5) width))
(concat code ": " name " (" gc-desc ")"))
((or (not width) (<= (+ lcode lname lgc 5) width))
(concat code ": " name " (" gc ")"))
((<= (+ lname lgc 3) width)
(concat name " (" gc ")"))
(t name)))))))