I would like to print face color attribute, below code just print the name. how to print the foreground color and background color?
(print 'font-lock-function-name-face)
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityYou can see the list of face attributes at face-attribute-name-alist
(defun dump-face-attributes (face &rest props)
(cl-loop for prop in (or props
(sort (mapcar #'car face-attribute-name-alist)
(lambda (s1 s2)
(string< (symbol-name s1) (symbol-name s2)))))
for val = (face-attribute face prop nil t)
unless (eq val 'unspecified)
append (list prop val)))
(defun get-face-attribute (face prop)
(plist-get (dump-face-attributes face prop) prop))
and you use it like this
(get-face-attribute 'font-lock-function-name-face :foreground)
(get-face-attribute 'font-lock-function-name-face :background)
(dump-face-attributes 'org-code)
Here is a sample session in M-x ielm
using above functions
*** Welcome to IELM *** Type (describe-mode) or press C-h m for help.
ELISP> (get-face-attribute 'font-lock-function-name-face :foreground)
"#4949d7"
ELISP> (get-face-attribute 'font-lock-function-name-face :background)
nil
ELISP> (dump-face-attributes 'org-code)
(:foreground "grey50" :inherit shadow)
You can use face-background/foreground
for that.
For example
(face-foreground font-lock-function-name-face)
(remember to also read face-foreground
its docstring)