junglee33 · 2022-10-22 14:54
hi all,
a package that i am using defines an a-list of various font properties f.e. 'family', 'weight', 'height' etc. etc.
i want to set values to these properties progammatically, f.e. on linux + my-home-machine i would want to set 'family' to say "Iosevka Mono", on my laptop i would use a high-dpi friendly font etc.
i wrote a trivial function like so:
(defun util:get-host-default-font-family ()
"return host specific font-family"
(interactive)
(cond ((utils:host-name-is "host-01") Iosevka Mono")
((utils:host-name-is "host-02") "Go Mono Regular")
((t "Consolas"))))
the "utils:host-name-is <name-of-host>" returns 'true' when current hostname matches the provided argument, 'false' otherwise. the above function does the right thing when called interactively on different hosts.
however, when i use it like so
(:default-family (util:get-host-default-font-family))
i get a
Wrong type argument: stringp, (util:get-host-default-font-family)
how do i fix it ?
--
thanks !
takeonrules · 2022-10-22 15:55
Wondering if `(:default-family ,(util:get-host-default-font-family))` would work? Note the `,` before the function call of `util:get-host-default-font-family`.
I also don't think your function need be `(interactive)`.
junglee33 · 2022-10-22 16:48
just tried that, unfortunately that invocation does not work. i get this
Wrong type argument: stringp, (, (util:get-host-default-font-family))
eleven_cupfuls · 2022-10-22 17:33
`(:default-family (util:get-host-default-font-family)` isn't enough context to say what's going wrong. You need to show the rest of the expression surrounding that.
jaw0 · 2022-10-23 02:50
your code above is missing a double quote around 'Iosevka Mono'
junglee33 · 2022-10-23 05:03
ah, yes it is. but that is unfortunately not the issue. fixing that does not really change anything…
junglee33 · 2022-10-27 06:05
sorry, for the slight delay in posting this, but i finally figured the problem out. just to give out some context, i am using [fontaine](https://protesilaos.com/emacs/fontaine) for font customizations. now, fontaine defines a 'fontaine-presets' variable which is just an alist of various font properties f.e. 'default-weight', 'default-height' etc. etc. for each font. it is defined like so
(setq fontaine-presets
'((tiny
:default-height 70)
(presentation
:default-height 120)
...
(t
:default-family "Iosevka"
:default-weight regular
...))))
given the above snippet, the problem is pretty obvious :o) [shoutout to u/eleven_cupfuls, for insisting on seeing wider context to the error message].
the trivial solution that i used is to split the alist config into host-agnostic, and host-specific parts (respectively) as follows
;; -----------------------------------------------------------------------------
;; these are the default font heights
(setq fontaine-presets
'((tiny
:default-height 70)
(small
:default-height 80)
(regular
:default-height 90)
(large
:default-height 110)
(presentation
:default-height 120)))
;; -----------------------------------------------------------------------------
;; setup host specific *default* fontaine-presets
(add-to-list 'fontaine-presets
(cond
;; host-1
((utils/host-name-is "host-1")
'(t
:default-family "PragmataPro Mono"
:default-weight regular
:default-height 90))
;; host-2
((utils/host-name-is "host-2")
'(t
:default-family "Go Mono Regular"
:default-weight regular
:default-height 90))
;; everything else
((t
'(t
:default-family "PragmataPro Mono"
:default-weight regular
:default-height 90)))))
this does the trick for me. i am *sure* there are far better ways to organize this, and would love it hear your suggestions etc. thank you u/takeonrules, u/jaw0 for your suggestions.
best regards !
cradlemann · 2022-11-20 09:00
I use chezmoi dotfiles manager to sync settings across different mashines. It support templatings, so you can specify different settings in one place. I also have different fonts on different mashines and one change will change font in any application I have, including GTK settings, etc
junglee33 · 2022-11-20 10:04
ah i see. thank you kindly for the suggestion. for now, i am using the snippet i posted earlier to do host specific configuration.
but ofcourse in a wider context chezmoi does seem to be quite promising.