reddit / emacs

Trying to get `fixed-pitch` face to inherit from the `default` face

realA12l · 2022-10-30 15:56
## Problem Characters in my org-mode blocks is fontified with the `Input Serif` font, but I want them to be fontified with the `PragmataPro Liga` font from the `default` face, when I set the `fixed-pitch` face to inherit from `default`. But when I manually set the `fixed-pitch` face to use the `PragmataPro Liga` font everything works as I want. Because it works as I intend when I set `fixed-pitch` directly to use `PragmataPro Liga` instead of inheriting that propoerty from `default` I conclude that I'm doing something wrong when I set `fixed-pitch` to inherit from `default`. I'm trying to figure out what I'm doing wrong mostly because this problem shows that there's a hole in my understanding of Emacs. ## Detailed description I've set the `fixed-pitch` face's `:family` attribute to `"unspecified"` and to inherit from the `default` face (set-face-attribute 'fixed-pitch nil :family "unspecified" :inherit 'default) wich makes `fixed-pitch` to have the attributes Family: unspecified Foundry: unspecified Width: unspecified Height: unspecified Weight: unspecified Slant: unspecified Foreground: unspecified DistantForeground: unspecified Background: unspecified Underline: unspecified Overline: unspecified Strike-through: unspecified Box: unspecified Inverse: unspecified Stipple: unspecified Font: unspecified Fontset: unspecified Extend: unspecified Inherit: default The `default` face have these attributes Family: PragmataPro Liga Foundry: FSD Width: normal Height: 128 Weight: regular Slant: normal Foreground: #000000 DistantForeground: unspecified Background: #ffffff Underline: nil Overline: nil Strike-through: nil Box: nil Inverse: nil Stipple: nil Font: #<font-object -FSD -PragmataPro Liga-regular-normal-normal-*-17-*-*-*-*-0-iso10646-1> Fontset: -FSD -PragmataPro Liga-regular-normal-normal-*-17-*-*-*-*-0-fontset-auto1 Extend: nil Inherit: nil My org-mode buffers in general use the `variable-pitch` face for styling because I've added `variable-pitch-mode` to the `text-mode-hook`. (add-hook 'text-mode-hook 'variable-pitch-mode) I've set the `variable-pitch` face font to `Input Sans`, so it has the attributes Family: Input Sans Foundry: FBI Width: normal Height: 128 Weight: regular Slant: normal Foreground: unspecified DistantForeground: unspecified Background: unspecified Underline: unspecified Overline: unspecified Strike-through: unspecified Box: unspecified Inverse: unspecified Stipple: unspecified Font: #<font-object -FBI -Input Sans-regular-normal-normal-*-17-*-*-*-*-0-iso10646-1> Fontset: unspecified Extend: unspecified Inherit: unspecified In no interface have I specified `Input Serif` as the font. `Input Serif` belongs to the same font family as `Input Sans`[1]. [0] https://github.com/protesilaos/modus-themes [1] https://input.djr.com/
lastnamebird · 2022-10-30 16:23
Try using the symbol `'unspecified` as the value for family, or omitting it altogether. I think using a string makes Emacs search for a font with that family name.
ForkInBrain · 2022-10-30 16:46
I don't think the magic value "unspecified" is a string. You tried this: (set-face-attribute 'fixed-pitch nil :family "unspecified" :inherit 'default) But I think you may want this: (set-face-attribute 'fixed-pitch nil :family nil :inherit 'default) or perhaps this (but probably not): (set-face-attribute 'fixed-pitch nil :family 'unspecified :inherit 'default) If I were you I would not bother using `set-face-attribute` at all, at least at the beginning. It is documented as being mainly for internal use. Instead do all your font face customization through `M-x customize-face`, which prevents this kind of lisp-level confusion. Emacs faces can be confusing enough as it is. When everything works as you like you can look at what customize has placed at the end of your `.emacs` or `init.el` file and attempt to replicate that in raw lisp. Or you can just leave it there and move on with your life. Your choice. By the way, I'm not sure, but I think all fonts inherit from 'default', so setting the family of 'fixed-pitch' to nil should be enough. That said, this may cause 'fixed-pitch' to not actually be fixed if 'default' happens to be a variable pitch font. As an aside, in Emacs documentation, when you see something quoted like 'this' or ‘this’ or `this' it is almost always meaning a lisp level symbol, or some other thing related to lisp code. Strings will be quoted like "this" or “this”.
realA12l · 2022-10-30 17:06
If I set (set-face-attribute 'fixed-pitch nil :family 'unspecified :inherit 'default) or use `customize-face` that generates the code (custom-set-faces '(fixed-pitch ((t (:inherit default))))) results in the `fixed-pitch` having the attributes Family: unspecified [...] Inherit: default which makes the text in org blocks to have the font `Input Sans`. And if I set (set-face-attribute 'fixed-pitch nil :family 'unspecified :inherit 'default) result in `fixed-pitch` having the attributes Family: Monospace [...] Inherit: default which makes the text in org blocks have the font `DejaVu Sans Mono`. > Instead do all your font face customization through M-x customize-face, which prevents this kind of lisp-level confusion. When everything works as you like you can look at what customize has at the end of your .emacs or init.el file and attempt to replicate that in raw lisp. Or not. Your choice. I tried that first, but I didn't understand what the `custom-set-faces` procedure does, and its documentation didn't make me any brighter (probably because I don't know Elisp); so I decided to try to learn how one should do it in manually written elisp. > As an aside, in Emacs documentation, when you see something quoted like 'this' or ‘this’ or `this' it is almost always meaning a lisp level symbol, or some other thing related to lisp code. Strings will be quoted like "this" or “this”. Thanks for the tip! When I wrote `"unspecified"` it looked like all other attribute values in `describe-face`, so I thought it was the correct way.
realA12l · 2022-10-30 17:07
See my answer to /u/ForkInBrain's post.
ForkInBrain · 2022-10-30 23:53
Have you tried just setting the `fixed-pitch` font family to what you want, rather than trying to inherit a font family from `default`? You linked to modus-themes in your original post. I looked around in that code and it looks like there are some delicate issues with respect to the interaction of `fixed-pitch` with other parts of Emacs. See these spots, but in general I'd read everyplace "fixed-pitch" is mentioned on in that file. https://git.sr.ht/~protesilaos/modus-themes/tree/main/item/modus-themes.el#L1512 https://git.sr.ht/~protesilaos/modus-themes/tree/main/item/modus-themes.el#L5964 https://git.sr.ht/~protesilaos/modus-themes/tree/main/item/modus-themes.el#L1205 https://git.sr.ht/~protesilaos/modus-themes/tree/main/item/modus-themes.el#L1505 https://git.sr.ht/~protesilaos/modus-themes/tree/main/item/modus-themes.el#L2950 P.S. these kinds of issues are one reason why I long ago gave up trying to tweak Emacs fonts and colors. I just use the defaults. They're fine on my system. I am really amazed when individual people do persevere and come up with a great looking theme, though. ;-)
realA12l · 2022-10-31 00:06
> Have you tried just setting the fixed-pitch font family to what you want, rather than trying to inherit a font family from default? I've, and when I manually set the `fixed-pitch` face to use the PragmataPro Liga font everything works as I want. You've to set the variable `modus-themes-mixed-fonts` (setq modus-themes-mixed-fonts t) to let the `modus-themes-fixed-pitch` face to inherit from `fixed-pitch`. Because everything works up to and including `fixed-pitch` in the inheritance hierarchy I drew the conclusion that there was something wrong between `fixed-pitch` and `default`. Are you suspecting a bug in the Modus themes?
organic-bookworm · 2022-11-01 17:45
> (add-hook 'text-mode-hook 'variable-pitch-mode) The `variable-pitch-mode` remaps `default` face to `variable-pitch` face. So `default` face attributes are overridden with corresponding **specified** `variable-pitch` attributes. See [Face Remapping](https://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Remapping.html). A `default` face is an **implicitly** inherited fallback face with **all attributes specified**. All faces **in the end** get `unspecified` attributes from `default` face. So `inherit`ing `default` face is the same as leaving it `unspecified`. See `default` face in [Basic Faces](https://www.gnu.org/software/emacs/manual/html_node/elisp/Basic-Faces.html). So, by setting `unspecified` font family for `fixed-pitch`, you get the font of `default` face, just as you wanted. It's just that due to remapping it now matches font of `variable-pitch`. Thus, you have to specify font explicitly. Maybe install [`mixed-pitch-mode`](https://gitlab.com/jabranham/mixed-pitch) instead of built-in `variable-pitch-mode` and add faces to preserve fonts for to `mixed-pitch-fixed-pitch-faces`.
realA12l · 2022-11-13 11:52
Thanks for the explanation!