oscarbonilla.com
4Jan/087

Beautiful Emacs (Windows Edition)

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

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

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 voilà! Beautiful Emacs once again.

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?

Tagged as: Leave a comment
Comments (7) Trackbacks (1)
  1. Hey, funny coincidence, I was just screwing around with emacs fonts on windows a couple of days ago. :) (On my new 170 DPI display). I too found that Inconsolata is blurry on windows; I guess the hinting is wrong or doesn’t work, or windows doesn’t support cleartype on otf fonts or something… haven’t cared enough to investigate. To my great surprise, I found Courier New (not the same as regular courier!) to be much nicer than Andale Mono. Now I will have to try Consolas. Thanks!

    BTW, a nice way to get the font name is something like (insert (prin1-to-string (w32-select-font)))

  2. Hm… if you zoom in on the pictures I posted (with ⌃ Scroll Wheel on a Mac), you can see that Inconsolata doesn’t seem to be using sub-pixel anti-aliasing at all!

  3. BTW, in case you don’t have a visual blahdiblah license, I’ve heard that it might be possible to cabextract the powerpoint viewer and grab consolas from there…

  4. As far as I know, the link from the webpage goes to the free Consolas font pack. You don’t need a visual studio license.

  5. Thanks for the emacs windows tips. I’ve always preferred the font “Bitstream Vera Sans Mono” for programming. It gives me an appealing “free” programmer’s font across all platforms.

    http://www.gnome.org/fonts/

    Thanks,
    -Jude

  6. ob, it looks free, but it won’t install unless you have a vs license on the machine

  7. Thanks exactly the information I needed.

    On windows a simpler way to get the font name is to enter the following line in the *scratch* buffer followed by C-J. It pops-up the windows font dialog.

    (w32-select-font nil t)


Leave a comment