7

Is there a way to change faces one at a time, outside of customize?

In my custom-file I see a big blob of face customizations that starts with:

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 ...

So I suppose custom-set-faces is not the right function to use for changing just one face, but I'm not sure what is.

Any suggestions?

2 Answers 2

4

You can use custom-set-faces or custom-theme-set-faces, with a list of one face - no problem. Or you can use modify-face. Or, as @erikstokes mentions, you can use set-face-attribute.

Note that the Elisp manual, node Attribute Functions, says this about set-face-attribute (but it doesn't say why):

This function is mostly intended for internal usage.

Note too that in the case of user options (variables), there are the single-option functions customize-set-variable and customize-set-value, which are companions to the multiple-option function custom-set-variables that is written to your custom-file (or init file). They are also commands, letting you choose the option using completion.

But for faces there is no such single-face companion function (and no command, other than customize-face).

2
  • For some reason custom-set-options does not appear in my custom-file (nor in C-h f custom-set-options). Instead, it uses custom-set-variables.
    – izkon
    Nov 10, 2018 at 18:25
  • Sorry, I meant custom-set-variables - I updated the answer to correct that.
    – Drew
    Nov 10, 2018 at 18:38
6

set-face-attribute is the function you want. For example to make comments green and bold:

(set-face-attribute 'font-lock-comment-face nil
  :foreground "Green"
  :weight 'bold)

There are also helper functions set-face-foreground and set-face-background for the common case of just changing the color of the face.

All of them can be executed via M-:, in a scratch buffer (C-x C-e), or put into ~/.emacs. The last 2 can also be executed via M-x.

To display the list of colors use M-x list-colors-display.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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