Thursday, August 10, 2006

Emacs: mapping file extensions to modes

I love emacs outline mode. When I'm making notes (like, trying to figure out the UI for supporting multiple save games) I usually start with a plain text file. After a while, I start organizing the notes. Soon, I start making headings with '*' and subheadings with '**'. Then I type M-x outline-mode and voila! I can expand or collapse headings and subheadings with a few keystrokes. And it's still, really, just a text file. Man, I love plain text files. Intensely. Yet platonically.

Today, I read this and thought to myself, "I should learn more about emacs so I, too, can have godlike programming power." It might be a bad thing if I had that kind of power, as anybody who bothers to read the source for nazghul will quickly discover, unless they turn into a pillar of salt first. But that's not my problem.

I already knew about outline modes, but today I had another thought (two in the same day!): I could save my outline files with a .olm extension, and modify my .emacs to automatically enter outine mode and turn on syntax highlighting whenever I open one. Syntax highlighting makes the little '**' marks pretty, and I like that, since it gives my eyes something to focus on while my mind wanders.

This is a very simple trick, but I'd forgotten how to do it. Luckily, I discovered that I'd already done it for javascript, and had a ready-made example. Are you ready? Here's how you do it:


(add-to-list 'auto-mode-alist (cons "\\.olm\\'" 'outline-mode))
(add-hook 'outline-mode-hook 'turn-on-font-lock)

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home