reddit / emacs

Emacs doesn't pick up the right font when starting it with emacsclient

zoliky · 2022-07-27 11:50
Hi, I have these font definitions in my init.el: ;; Default (set-face-attribute 'default nil :font "Hack" :height 180) ;; Variable-pitch (set-face-attribute 'variable-pitch nil :font "Hack" :height 180) ;; Fixed-pitch (set-face-attribute 'fixed-pitch nil :font "DejaVu Sans Mono") (defun custom/org-fixed-pitch () (set-face-attribute 'org-table nil :inherit 'fixed-pitch) (set-face-attribute 'org-block nil :inherit 'fixed-pitch :foreground nil) (set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch))) When Emacs starts with `emacsclient -c` the `Hack` font is not used. Probably the others font settings are ignored as well. Also, I noticed that my org agenda files don't load up when `emacsclient -c` is used. They don't show up in the buffers. I would be grateful for any suggestion.
alebrick · 2022-07-27 12:28
For the font issue, I had the same problem long ago. The solution is to add a hook to `after-make-frame-functions`, which will accept a frame as a parameter. You can pass that frame to the call to `set-face-attribute`.
zoliky · 2022-07-27 12:51
This is what you mean? (if (daemonp) (add-hook 'after-make-frame-functions (lambda (frame) (set-face-attribute 'default nil :font "Hack" :height 180)))) But that means I need to define each font twice. Once, when emacs starts with `emacs` and the second time inside the `if (daemonp)` when emacs starts with `emacsclient -c` I want them to work for both cases.
rockatanescu · 2022-07-27 13:30
I believe you want to specify the `family`, not `font`, like this: (set-face-attribute 'default nil :family "Hack" :height 180) (set-face-attribute 'variable-pitch nil :family "Hack" :height 180) (set-face-attribute 'fixed-pitch nil :family "DejaVu Sans Mono")
[deleted] · 2022-07-27 13:44
[deleted]
shami1kemi1 · 2022-07-27 14:02
You can refactor it so that it works in both cases. [For example, here's the way I do it in my config.](https://gitlab.com/sham1/.emacs.d/-/blob/master/init.el#L232-242)
zoliky · 2022-07-27 14:45
Thank you. The org agenda files show up in the buffer list if I run `org-agenda-list` with M-x but if I restart the Emacs daemon again, I need to run `org-agenda-list` again for them to show up.
zoliky · 2022-07-28 17:05
What is the difference between ":family" and ":font"?
rockatanescu · 2022-07-29 11:22
According to [the manual](https://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html), `:family` expects a font family name (like `Hack` or `Iosevka`), while `:font` expects a font object or a fontset. This is how I set the fonts for Emacs (v28.1) in my personal config file: (set-face-attribute 'default nil :family "Iosevka Term SS08" :height 135) (set-face-attribute 'fixed-pitch nil :family "Iosevka Term SS08" :height 135) (set-face-attribute 'variable-pitch nil :family "Iosevka Aile" :height 135) I generally use emacsclient to start emacs instances and the above setup works just fine for me.