Håkon Hægland
Håkon Hægland

Reputation: 40778

How to set frame font in Emacs

I would like to change the font in Emacs from within a major mode. I am using Emacs 24.3 on Ubuntu 12.04.

I tried set-frame-font, like:

(set-frame-font "DejaVu Sans Mono-10")

But I get error:

Debugger entered--Lisp error: (error "Font not available" #<font-spec nil nil DejaVu\ Sans\ Mono nil nil nil nil nil 10.0 nil nil nil ((:name . "DejaVu Sans Mono-10") (user-spec . "DejaVu Sans Mono-10"))>)
  internal-set-lisp-face-attribute(default :font "DejaVu Sans Mono-10" #<frame [email protected] 0x116a4c0>)

The output of fc-list is:

fc-list | grep 'DejaVu Sans Mono'

DejaVu Sans Mono:style=Bold Oblique
DejaVu Sans Mono:style=Oblique
DejaVu Sans Mono:style=Book
DejaVu Sans Mono:style=Bold

Upvotes: 4

Views: 2464

Answers (1)

Chris
Chris

Reputation: 137088

It sounds like you've built Emacs without Xft support, which is required if you want to use anti-aliased, TrueType, and OpenType fonts.

Here is how you can build it with Xft:

  1. Install the libxft-dev package, which contains the required Xft headers:

    sudo apt-get install libxft-dev
    
  2. Build Emacs as before, but this time include the --with-xft flag in your ./configure command.

Now your Emacs should be able to use TrueType and OpenType fonts, including DejaVu Sans Mono.

Upvotes: 4

Related Questions