I have a custom (custom-set-faces ...) section in my ~/.emacs file. When I run emacs this section seems to get completely ignored since the custom colours don't get set. But if I go to ~/.emacs, highlight the section and run it with M-x eval-region then the colours load correctly. Why is custom-set-faces getting silently ignored?
1 Answer
Add
(add-hook 'emacs-startup-hook (lambda () (custom-set-faces "Put your original “(custom-set-faces ...)” here!"))) to your configuration.
I guess the problem you encountered has to do with the order of actions at Emacs startup:
When Emacs is started up, it performs the following operations (see
normal-top-levelinstartup.el):
- If appropriate, it creates a graphical frame. As part of creating the graphical frame, it initializes the window system specified by
initial-frame-alistanddefault-frame-alistfor the graphical frame, by calling thewindow-system-initializationfunction for that window system. This is not done in batch (noninteractive) or daemon mode.- It initializes the initial frame’s faces, and sets up the menu bar and tool bar if needed. If graphical frames are supported, it sets up the tool bar even if the current frame is not a graphical one, since a graphical frame may be created later on.
- Is there a way to make this work both in daemon mode and in normal mode? While I run Emacs by daemonizing it, I also have it as my default git commit message editor. With your proposed solution all seems to work fine in daemon mode, but when editing git messages in standalone mode fonts are not customized properly.Jan Stolarek– Jan Stolarek2023-06-27 17:37:24 +00:00Commented Jun 27, 2023 at 17:37
- @JanStolarek I was able to get the behavior you desire by adding this line after the
(add-hook...)code:(add-hook 'emacs-startup-hook \n face-customizer)where the\nis a new line.mikemtnbikes– mikemtnbikes2023-08-28 14:58:03 +00:00Commented Aug 28, 2023 at 14:58 - @mikemtnbikes: You can omit that
newline.shynur– shynur2023-08-28 15:01:33 +00:00Commented Aug 28, 2023 at 15:01 - @shynur Thanks for note, I figured it was unnecessary, but wasn't sure.mikemtnbikes– mikemtnbikes2023-08-28 15:05:21 +00:00Commented Aug 28, 2023 at 15:05
emacsclient?custom-set-facessets the face of frameF1, which is actually invisible. I encountered this issue yesterday...custom-set-facescode, at least the relevant part.custom-set-faces. I tried callingcustom-set-facesby putting it inside the hook like this:(defun efs/set-font-faces () (custom-set-faces ...)), but that does not seem to work.