0

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)

2 Answers 2

1

You 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)
0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.