Function: icon-string
icon-string is a byte-compiled function defined in icons.el.gz.
Signature
(icon-string NAME)
Documentation
Return a string suitable for display in the current buffer for icon NAME.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/icons.el.gz
(defun icon-string (name)
"Return a string suitable for display in the current buffer for icon NAME."
(let ((props (iconp name)))
(unless props
(user-error "%s is not a valid icon" name))
(pcase-let ((`(_ ,spec _ ,keywords) props))
(setq spec (icon-complete-spec name))
;; We now have a full spec, so check the intersection of what
;; the user wants and what this Emacs is capable of showing.
(let ((icon-string
(catch 'found
(dolist (type icon-preference)
(let* ((type-spec (assq type spec))
;; Find the keywords at the end of the section
;; (if any).
(type-keywords (icon-spec-keywords type-spec)))
;; Go through all the variations in this section
;; and return the first one we can display.
(dolist (icon (icon-spec-values type-spec))
(when-let* ((result
(icons--create type icon type-keywords)))
(throw 'found
(if-let* ((face (plist-get type-keywords :face)))
(propertize result 'face face)
result)))))))))
(unless icon-string
(error "Couldn't find any way to display the %s icon" name))
(when-let* ((help (plist-get keywords :help-echo)))
(setq icon-string (propertize icon-string 'help-echo help)))
(propertize icon-string 'rear-nonsticky t)))))