Archive for the 'emacs' Category

Emacs Notes for Summer 2008

Every now and then, I re-evaluate and switch up the emacs version that I use. Often this is driven by a major OS upgrade, like Panther->Tiger or Tiger->Leopard. Sometimes it’s just because it’s been a while, or something that has been bugging me, and I’ve reached the breaking point. Or I want to avoid real work for an hour.

In the version of Carbon Emacs I used for Tiger (which I had built myself from GNU sources), I had some emacs lisp that would set the default font on startup. The built in default font was too big for my tastes, and it was consequently anti-aliased. I really don’t like anti-aliased fonts in my editors and terminals.

For some reason, this lisp no longer worked in the Carbon Emacs I had to start using for Leopard. In fact the little dialog box that you could pop up a standard Mac font selector window didn’t even work, so I couldn’t change the font from the default Monaco 12-point anti-aliased font. I’ve been suffering this cruelty for over 6 months.

Today I tried a number of recipes for getting a newer emacs (I wanted to try 22.2), but they failed. I ended up using this hack:

First, download emacs 22.2 sources from GNU.


cd emacs-22.2
sudo cp -R mac/Emacs.app /Applications/Emacs.app
sudo cp /usr/bin/emacs /Applications/Emacs.app/Contents/MacOS

My old lisp still didn’t work the way it used to, but part of it did:

(global-set-key "\C-x\C-t" 'mac-font-panel-mode)

This allows me to bring up the little Mac font selector window. Then some apropos work turned up “set-default-font.” Mac fonts on Emacs have seriously inscrutable names. But if you interactive run M-x set-default-font and then hit ? when it asks which font, you get a nice listing of ALL the crazy Emacs-ized mac font names.

The font I wanted was:


(set-default-font "-apple-monaco-medium-r-normal--10-90-72-72-m-90-mac-roman")

That’s Monaco 10 point. So I just stuff that in my emacs lisp initialization file along with:


(global-font-lock-mode 1)
(set-frame-width (selected-frame) 90)
(set-frame-height (selected-frame) 80)
(set-frame-position (selected-frame) 1 6)

And my Emacs is ready to use when it starts up. Just like back in 1991 on my SPARCstation 2.

My Long Lost Twin Brother.

Steve Yegge is my long lost, slightly smarter, twin brother. His recent rants have convinced me of that fact, to a scary degree. (Loves emacs, worships JWZ, not a Mac nut yet has switched, hates IDEs)

Bad news for you, Stevie, is that you’re really 41, not 40. Or maybe I’m 40, not 41. That’s a better thought.

How to scroll compiler output in Emacs

I’ve used M-x compile in emacs for years. Like for 17 years. My fingers automatically do ^x^m that I have had as the key binding for that command, as soon as I save a source file.

However, at some point in Emacs 21 (and now on 22) the *compilation* buffer stopped scrolling; it would show the top of the output, but then scroll out of sight. Then I would have to move the point to the end of that buffer to see the compilation activity. It was very annoying, but not annoying enough that I spent any time trying to find the settings.

But I did finally stumble across it, and here it is:


(setq compilation-scroll-output t)

One more line in my 5000 lines of emacs personalization lisp.

Tutorial on making an emacs major mode.

At work, we have these message declaration files for localizing the application. I wanted to make an emacs mode where at least the message identifiers were highlighted in a different color. I found this nice tutorial on getting started with the hooks.

It only took me 10 minutes to get my mode working well enough. Here is my mode, as an example.

(defvar r9msg-mode-hook nil)

(defvar r9msg-mode-map
  (let ((r9msg-mode-map (make-keymap)))
    ;;(define-key r9msg-mode-map "\C-j" 'newline-and-indent)
    r9msg-mode-map)
  "Keymap for r9msg majo mode")

(add-to-list 'auto-mode-alist '("\\.msg\\'" . r9msg-mode))

; comments begin with #
; msg ids begin with *
; directives begin with @
(defvar r9msg-font-lock-keywords-1
  (list
   '("^#.*" . font-lock-comment-face)
   '("^\\*.*" . font-lock-constant-face)
   '("^@.*" . font-lock-variable-name-face)
   )
  "Minimal highlighting expressions for r9msg mode")

(defvar r9msg-font-lock-keywords
  r9msg-font-lock-keywords-1)

(defun r9msg-mode ()
  "Major mode for editing msg files"
  (interactive)
  (kill-all-local-variables)
  (set (make-local-variable 'font-lock-defaults)
       '(r9msg-font-lock-keywords))
  ;;(set-syntax-table r9msg-mode-syntax-table)
  (use-local-map r9msg-mode-map))

set emacs coding system

Every now and then I try to create a new XML file in emacs. It’s something I don’t do that much, because I hate XML. Hate it. But that’s a rant for another day.

The problem I run into is that when you make a new buffer in emacs, it sets the default encoding scheme to iso-latin-1. And, of course, XML is (by definition) utf-8. Emacs tries to be all helpful and says “hey billo you idiot, iso-latin-1 is wrong. change it.” Naturally, it doesn’t tell me how to change it. So I always waste time trying to remember how to fix the encoding. Since I can’t remember anything, I’m writing this note so I can waste less time in the future. I hope I remember I wrote this note.

The solution is:

M-x set-buffer-file-coding-system

Answer: utf-8

TextMate is a good editor.

I’ve been an emacs user for 20 years. Gosh, that is scary. Every now and then I try to use a different, “modern” editor or IDE for a while. Visual Studio. Borland JBuilder. Eclipse. TPU. (ha! just kidding. I used TPU before I used emacs).

I always end up going back to emacs.

Since I’ve been experimenting with Ruby on Rails, I’m trying TextMate. It has emacs-ish basic bindings, so it’s tolerable out of the gate. It has a nice, simple, but powerful extension mechanism, with a lot of pragmatic tools that cover all the languages I care about. It also has very nice Rails support, apparently because all the Railserati use it. Watch the video demo, and you might want to try it to.

So far, I’ve used it long enough to actually pay the shareware fee. I really like it. Let’s see if I’m still using it in a month.

Emacs and OS X

I always knew Tim Bray was smart, but hist pitch on emacs makes me a huge fan. (I’m always a huge fan of people who are smart and agree with me.)

He, in turn, references Neal Stephenson’s essay about open source, emacs and operating systems, which is a classic, and worth referencing again.

technorati tags:

emacs on tiger?

Everything was going swimmingly on my foolish, headlong migration to Tiger until I tried to run the Aqua version of emacs. It wouldn’t even start. After some grunging around, and some help from Derek, I have a build that is working.

The secrets are:

  1. Fetch the latest version of emacs from CVS.
  2. configure with “–with-carbon and –without-x”

My build is in progress. I’m keeping my fingers crossed.

Update: Yay, it worked. Here it is: EmacsInstaller.dmg