0

I share my Emacs config across several machines, and I can't necessarily guarantee that they will all have the same fonts installed. For this reason, I would like to be able to give Emacs a list of acceptable fonts to use and have it select the first available font from that list at startup and set the default face to use that font. This should give me a reasonable-looking Emacs on any system. Is there a way to do this by default, or a package that implements it, or will I have to write my own code for this?

  • One idea would be to use something like (x-list-fonts "*") and compare the resulting list to each item in your custom list in order of preference and to signal a hit/break when a match is found ... – lawlist Jun 5 at 19:03
1

You could just set the face-font-family-alternatives variable:

-- User Option: face-font-family-alternatives
    If a given family is specified but does not exist, this variable
    specifies alternative font families to try.  Each element should
    have this form:

         (FAMILY ALTERNATE-FAMILIES...)

    If FAMILY is specified but not available, Emacs will try the other
    families given in ALTERNATE-FAMILIES, one by one, until it finds a
    family that does exist.

Use C-h v to see its current value; it's probably already got some alternatives for certain family names. Here's the value my Emacs currently has:

(("Monospace" "courier" "fixed")
 ("Monospace Serif" "Courier 10 Pitch" "Consolas" "Courier Std" "FreeMono" "Nimbus Mono L" "courier" "fixed")
 ("courier" "CMU Typewriter Text" "fixed")
 ("Sans Serif" "helv" "helvetica" "arial" "fixed")
 ("helv" "helvetica" "arial" "fixed"))
| improve this answer | |
  • So basically I could add an element like ("My Fonts" "Font1" "Font2" "Font3") to face-font-family-alternatives and then tell the default face to use "My Fonts" as the font? – Ryan C. Thompson Jun 5 at 20:17
  • Yes, or you could use whatever is most commonly available on all of your machines. – db48x Jun 5 at 20:36

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.