Function: marginalia--variable-value
marginalia--variable-value is a byte-compiled function defined in
marginalia.el.
Signature
(marginalia--variable-value SYM)
Documentation
Return the variable value of SYM as string.
Source Code
;; Defined in ~/.emacs.d/elpa/marginalia-20260724.810/marginalia.el
(defun marginalia--variable-value (sym)
"Return the variable value of SYM as string."
(cond
((not (boundp sym))
(propertize "#<unbound>" 'face 'marginalia-null))
((and marginalia-censor-variables
(let ((name (symbol-name sym))
case-fold-search)
(cl-loop for r in marginalia-censor-variables
thereis (if (symbolp r)
(eq r sym)
(string-match-p r name)))))
(propertize "*****"
'face 'marginalia-null
'help-echo "Hidden due to `marginalia-censor-variables'"))
(t
(let ((val (symbol-value sym)))
(pcase val
('nil (propertize "nil" 'face 'marginalia-null))
('t (propertize "t" 'face 'marginalia-true))
((pred keymapp) (propertize "#<keymap>" 'face 'marginalia-value))
((pred bool-vector-p) (propertize "#<bool-vector>" 'face 'marginalia-value))
((pred hash-table-p) (propertize "#<hash-table>" 'face 'marginalia-value))
((pred syntax-table-p) (propertize "#<syntax-table>" 'face 'marginalia-value))
;; Emacs bug#53988: abbrev-table-p throws an error
((guard (static-if (< emacs-major-version 30)
(and (vectorp val) (ignore-errors (abbrev-table-p val)))
(abbrev-table-p val)))
(propertize "#<abbrev-table>" 'face 'marginalia-value))
((pred char-table-p) (propertize "#<char-table>" 'face 'marginalia-value))
;; Callable objects or object closures (OClosures)
((guard (oclosure-type val))
(format (propertize "#<oclosure %s>" 'face 'marginalia-function) (oclosure-type val)))
((pred byte-code-function-p) (propertize "#<byte-code-function>" 'face 'marginalia-function))
((and (pred functionp) (pred symbolp))
;; We are not consistent here, values are generally printed
;; unquoted. But we make an exception for function symbols to visually
;; distinguish them from symbols. I am not entirely happy with this,
;; but we should not add quotation to every type.
(format (propertize "#'%s" 'face 'marginalia-function) val))
((pred recordp) (format (propertize "#<record %s>" 'face 'marginalia-value) (type-of val)))
((pred symbolp) (propertize (symbol-name val) 'face 'marginalia-symbol))
((pred numberp)
(propertize (number-to-string val)
'face 'marginalia-number
'help-echo (and (integerp val)
(format "%d, #o%o, #x%x%s" val val val
(if (characterp val) (format ", ?%c" val) "")))))
(_ (let ((print-escape-newlines t)
(print-escape-control-characters t)
;;(print-escape-multibyte t)
(print-level 3)
(print-length marginalia-field-width))
(propertize
(replace-regexp-in-string
;; `print-escape-control-characters' does not escape Unicode control characters.
"[\x0-\x1F\x7f-\x9f\x061c\x200e\x200f\x202a-\x202e\x2066-\x2069]"
(lambda (x) (format "\\x%x" (string-to-char x)))
(prin1-to-string
(if (stringp val)
;; Get rid of string properties to save some of the precious space
(substring-no-properties
val 0
(min (length val) marginalia-field-width))
val))
'fixedcase 'literal)
'face
(cond
((listp val) 'marginalia-list)
((stringp val) 'marginalia-string)
(t 'marginalia-value))))))))))