After fixing the font on my Carbon Emacs on Mac OS X, I’m spoiled with good fonts. Today I had to work on Windows and naturally, the only way to make Windows liveable is to work inside Emacs.

This is what a default installation of EmacsW32 looks like.

EmacsW32 Courier
EmacsW32 Courier

Oh horror! You guys are kidding, right? Courier? Seriously?

Naturally, my first inclination was to use Inconsolata again. Just like in Mac OS X. However, this is what Inconsolata looks like.

Emacs W32 Inconsolata
Emacs W32 Inconsolata

WTF? What’s with all the blurred text? Well, it turns out that anti-aliasing and text rasterization differ significantly between Mac OS X and Windows. Oh well. Scratch that plan.

Then I remembered that Incosolata is actually based on Consolas, which is a font Microsoft created specifically for programming.

I downloaded and installed Consolas, and voila! Beautiful Emacs once again.

EmacsW32 Consolas
EmacsW32 Consolas

Now it was just a matter of figuring out what the font was called. I had changed the font by clicking on the Emacs frame and pressing the shift key. In order to see what that does, I ran the describe‑key function by typing C‑h k, then clicking on the frame while holding the shift key. That told me the function that is called is mouse‑set‑font and it’s defined in c:/Program Files/Emacs/emacs/lisp/term/w32-win.elc. You can click on the file link and Emacs will take you to the function definition.

(defun mouse-set-font (&rest fonts)
  "Select an Emacs font from a list of known good fonts and fontsets.

If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
font dialog to display the list of possible fonts.  Otherwise use a
pop-up menu (like Emacs does on other platforms) initialized with
the fonts in `w32-fixed-font-alist'.
If `w32-list-proportional-fonts' is non-nil, add proportional fonts
to the list in the font selection dialog (the fonts listed by the
pop-up menu are unaffected by `w32-list-proportional-fonts')."
  (interactive
   (if w32-use-w32-font-dialog
       (let ((chosen-font (w32-select-font (selected-frame)
   w32-list-proportional-fonts)))
 (and chosen-font (list chosen-font)))
     (x-popup-menu
      last-nonmenu-event
      ;; Append list of fontsets currently defined.
      ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
      (if (fboundp 'new-fontset)
      (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
  (if fonts
      (let (font)
(while fonts
  (condition-case nil
      (progn
                (setq font (car fonts))
(set-default-font font)
                (setq fonts nil))
    (error (setq fonts (cdr fonts)))))
(if (null font)
    (error "Font not found")))))

Now, I don’t know what all of that does, but it seems like (set‑default‑font font) is the one function that actually sets the font. In order to figure out what the font is called, I copied all of the function to the good old scratch buffer, and added a call to (message font) right after the call to (set‑default‑font font). Then I redefined the function by typing C‑x C‑e at the end of it. After shift clicking on the frame again and selecting the Consolas font I had all the information I needed.

Now it was just a matter of putting the following snippet in my .emacs file:

    (set-default-font
     "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-iso8859-1")

Ahh…​ I feel so much better now…​ now what was I doing in Windows again?