oscarbonilla.com

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?

Written by ob

January 4th, 2008 at 5:03 pm

Posted in Emacs

Tagged with

11 Responses to 'Beautiful Emacs (Windows Edition)'

Subscribe to comments with RSS or TrackBack to 'Beautiful Emacs (Windows Edition)'.

  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)))

    timjr

    6 Jan 08 at 2:19 pm

  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!

    ob

    11 Jan 08 at 4:17 pm

  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…

    timjr

    16 Jan 08 at 3:43 pm

  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.

    ob

    16 Jan 08 at 7:04 pm

  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

    Jude

    21 Jan 08 at 9:32 am

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

    timjr

    1 Feb 08 at 4:22 pm

  7. [...] Bonilla wrote posts on how to prettify emacs for OS X and later on for Windows. The rather excellent EmacsW32 package is now based on a build of Emacs [...]

  8. 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)

    boyd

    14 Jun 09 at 7:09 am

  9. @timjr – I installed the package on my machine and it installed fine, I don’t have any VS license.

    ZZamboni

    5 Apr 10 at 2:28 pm

  10. You can actually just use:

    (set-face-attribute ‘default nil :font “Consolas-12″)

    This sets the `font’ face attribute on the `default’ font to “Consolas-11″ on all frames (that’s what the `nil’ does).

    Deniz Dogan

    23 Aug 11 at 6:34 am

  11. TYVM for the font, I needed such a good one.

    By the way, just do M-x describe-fontset to retrieve the font description. It’s way simpler than your method.

    Good job and TY though!!

    vectraproject

    19 Nov 12 at 5:55 pm

Leave a Reply