Emacs to TextMate, Part 1

Posted by Nick Sieger Fri, 13 Oct 2006 03:20:00 GMT

My name is Nick Sieger, and I’m an Emacs-o-holic. I’ve been using Emacs for over a decade, and my .emacs file alone (excluding custom elisp packages) has accumulated 125KB of cruft. Basic navigation keystrokes are beyond ingrained into my fingers, they’re automatic. I was pleased when I found Jacob Rus’ explanation of the Cocoa text system and accompanying instructions for baking these commands into the basic OS X text widget; now getting around Cocoa text widgets is a breeze.

Emacs, in a way, has a reputation for being something like the Spruce Goose of computer programming tools. Some view it as the pinnacle of achievement in text editing tools; a piece of art; the most extensible piece of software ever written. On the other hand, the learning curve is considered to be much steeper, and Emacs hasn’t changed visually very much over the years, sticking to a minimalist interface that doesn’t dazzle like tabby, tree-widgety, multi-paneled IDEs.

So it seems that I’m going to be continually comparing TextMate to Emacs; perhaps a subject worth expounding upon. As I ramp up on TextMate, maybe these findings and tips will become useful for anyone, Emacs user or not.

Things to like about TextMate

  • The “project” system is simple but elegant in its conception. Open a directory, and it becomes your workspace. Navigate to any file quickly with ⌘-T. I always wanted something like this in Emacs and considered writing one at one point.

  • Visually appealing. Renders fonts well, beautiful built-in color schemes, strong syntax-highlighting. The multiple, nested context highlighting is well done. At the same time, the UI is minimalist enough that you’re not distracted by gratuitous toolbars full of icons that you constantly have to hover for the tooltip to remember what they do.

  • Feels right. The app blends in well with the OS X user interface, and shares its philosophical underpinnings of simplicity and least surprise.

  • Broad language support. Many popular languages supported out of the box (notable exception: C# -- I wonder why), and if you get subversion bundles, many less common ones, e.g., Io, Lua, or OCaml (note to self: none of which I have had the chance to explore yet).

  • Community support and innovation. Seeing the buzz in the community around TextMate is strong evidence that it’s spurring some innovation, a fresh approach, in a category of software that hasn’t seen much for quite some time.

Emacs-isms I miss (or haven’t found yet) in TextMate

  • Text selection while staying on the home row. Setting the mark (C-SPC) and moving the cursor to select a region of text. I don’t like moving my right hand over to the arrow keys to make a selection! This is my number one new feature wish for TextMate.

  • Buffer selection with C-x b or C-x C-b to quickly jump to an already-open file. ⌘-T replaces this to some extent, but it’s not the same and requires some retraining. Update: ⌘-T RET is equivalent to C-x b. Good enough. One thing I have discovered that I like quite a bit is the ability to scroll through the buffer/file-selection box with C-n and C-p.

  • back-to-indentation. This is an emacs command that moves the cursor in front of the first non-whitespace character on the line and is bound to M-m by default. This keystroke is apparently one that I use frequently, because my fingers keep typing ⌘-M which has the effect of minimizing the current window in TextMate. Ack.

  • open-line in Emacs is bound to C-o, which inserts a new line where the cursor is but leaves the cursor before it. The exact same command is in TextMate, and is bound to the same key. Sweet! But apparently my fingers are trained on a variation: split-line, bound to C-M-o. This is similar to open-line except that it moves any text to the right of the cursor vertically down. When you’re sitting at the first non-whitespace character on a line and you split it, it has the effect of creating a new line directly above the current one, leaving you at the same indentation level. Yes, C-a C-o TAB pretty much does the same thing, but it’s three keystrokes instead of one.

  • hippie-expand is a powerful, extensible multi-completion mechanism that is hard to live without. TextMate’s ⎋ completion seems roughly equivalent to Emacs’ dabbrev-expand, but hippie can expand similar words and lines from all open buffers, making the completion that much more powerful and context-aware.

  • recenter (C-l). Puts the current line in the middle of the window, unconditionally. TextMate doesn’t appear to let you scroll the contents of the window such that the last line in the buffer is any higher than the bottom of the window. I prefer to have the line of code I’m editing closer to the center of the window.

  • string-rectangle. This versatile command allows you to replace each line in a rectangular selection with a prompted string value. Great for adding a column of tab characters, commas or other formatting to a group of similar lines. Update: I found the TextMate equivalent for this one. It turns out TextMate has a great rectangular editing facility, simply by starting a selection, tapping ⌥, and continuing. Typing while the rectangle is active inserts new text in the same manner as string-rectangle. Excellent.

What else have you found about TextMate that reminds you of Emacs or helps you get over it?

To be continued!

Posted in  | Tags , ,  | 14 comments | no trackbacks


  1. Avatar JEG2 said about 10 hours later:
    Interesting comparison. For buffer cycling there is ⌘` to rotate through windows and ⌥⌘← and ⌥⌘→ to rotate through the tabs of a project. Just FYI, I am currently writing a book on TextMate, now available as a beta book from: http://www.pragmaticprogrammer.com/titles/textmate/index.html
  2. Avatar grant said about 11 hours later:

    If you haven’t already, you should add some more Emacs-isms to your OS X key bindings.

  3. Avatar grant said about 12 hours later:

    Oops... I managed to completely miss the sentence where you wrote about the exact same thing.

  4. Avatar alan said about 13 hours later:

    My own emacs to textmate experience is here, in case you’re interested. I was motivated by a number of similar things as you, project management in particular. It’s been six months and I still find myself reaching for an emacs-ism every once in a while.

    One command that I didn’t stumble across for quite a while is cmd-ctrl-t, which pops open a “select bundle item” box -- type a partial bundle command to narrow down the list and find the command you’re looking for. It’s a pretty useful sort of cousin to emacs’ M-x command completion.

  5. Avatar Martin Ström said about 13 hours later:

    As for the open-line: You can record a macro to do that ⌃A ⌃O ⇥ and bind it to ⌃O to overide the default behaviour and make it work as you want.

  6. Avatar Jacob Rus said 1 day later:

    Thanks for the compliment!

    A few notes:

    • Allan knows that people want mark points, and is I think planning to add them at some point. I don’t think there’s any specific time frame for that though.

    • The “back to indentation” thing is a trivial macro you can make yourself in 20 seconds.

    • you should be able to make a command/macro for split line without much trouble. The macro would be something like: select to beginning of line, copy, move right, newline, paste, select to beginning of line, find “S” and replace inside selection with ” “, using regular expressions, (optionally convert spaces to tabs), move right, move up.

    • you’ll need to explain hippie-expand. I have no idea what that is

    • recenter works fine. Just keep some extra newlines at the end of your code.

  7. Avatar Jacob Rus said 1 day later:

    Oh, I didn’t understand what you wanted for split line.

    You can very easily make a cocoa key binding for what you want, or do it as a macro in textmate.

  8. Avatar Nick said 2 days later:

    Thanks all for the suggestions.

    Looks like my spare time at some point in the future should be examining extensibility.

    I’ll queue explanation of hippie-expand for a future post, perhaps if there’s interest I could look at learning how to build such a feature in TextMate.

  9. Avatar evan said 5 days later:

    I’m an emacs guy considering switching to TextMate as well. So far i like what i see, but the indentation is really bothering me. I really like to have things indented like this:

    public foo(int bar, int rubarb);

    (of course, i realize that this page might not be in a monospace font, so what i’m trying to do is have those two int’s lined up one on top of the other)

    TextMate only seems to insert tabs for the level of indentation, not caring to line things up with tabs and spaces with in parenthesis.

    Does this not bother you? And if it does, how do you get around it?

  10. Avatar Nick said 6 days later:


    I can’t say it doesn’t bother me. I’ve never seen anything like a well-customized cc-mode on Emacs on any other editor, and I’m surprised because it’s so slick.

    I guess you could say I’m looking the other way at some of TextMate’s deficiencies and trying to appreciate what it brings to the table. Over time, I’d expect more and more of the really good emacs-isms to show up in TM, and I hope to contribute some of my own as well.

  11. Avatar Paul Bissex said 14 days later:

    I haven’t used hippie-expand, but from your description it sounds similar to Michael Tsai’s BBAutoComplete. One of the only BBEdit features I’ve missed after moving to TextMate.

  12. Avatar John Wiegley said 65 days later:

    As an Emacs user (and contributor) since almost a decade ago, I’ve found many things to like in TextMate, and some that make me cringe. Here is my own little list, after trying out TM on a some heavy ASP.NET modifications:

    • TM’s hierarchical analysis of languages is wonderful. Also, it’s a feature that will never make it into Emacs without an enormous rewrite. Emacs has “major modes” for particular languages, but you can’t really have “sub-major modes” for languages within languages. The module mmm.el doesn’t even come close to being as functional as TM.

    • The UTF-8 handling is nice too. I know I can set it up that way in Emacs, but TM makes it more natural.

    • As for TM’s “project” system, Emacs has had speedbar.el since long before TM even existed. There’s nothing really new here.

    • TM’s developer must really like his mouse. I find this to be the case with many Mac programs. The selection and movement commands feel immature to me as an Emacs user. Also, there are far too many “chords” that want 3-4 keys pressed simultaneously. After just a few minutes of usage, it became abundantly clear that TM’s author never thought of the Dvorak layout. I simply cannot type Ctrl-Shift-J without severe discomfort, and it’s unfortunately a command I use a lot. And what about Ctrl-Opt-Cmd-P? Impossible.

    What makes things worse is that TM’s context-based commands are bound to specific keys, not key “patterns”. If all the Ctrl-Opt-Cmd-P commands had been bound to a virtual key called “Preview” -- which I could later rebind to something else -- I wouldn’t care. But instead I have to remap every command that references it, without any good way to locate them all at once.

    • I like TM’s integration with the OS/X environment. What originally moved me from vi to Emacs was Emacs’ editing environment -- not its keybindings. What may move me to TM is a similar leap, since I find that it’s the environment that makes me productive, not the individual editing keystrokes.
  13. Avatar Nick said 66 days later:

    Hey John, thanks for posting your thoughts. I’ve been a fan of your Emacs packages for a long time, so it’s great to hear from a well-known power Emacs user who has also crossed over.

    Agree with you on many of your points. I also don’t like the proliferation of 3-modifier keystrokes (was that Ctrl-Shift-Option-P or Ctrl-Option-Command-P?).

    After a couple of months more of TM usage, I still miss hippie-expand and Emacs’ help system, e.g., C-h k the most.

  14. Avatar sjk said 80 days later:
    … and Emacs’ help system, e.g., C-h k the most.

    Just this morning I was thinking, as a TM newcomer (since a few days) and Emacs old-timer (since the original Teco-based version), how useful something analogous to Emacs’ excellent integrated, self-documenting-supporting help system would be, especially describe-key/bindings style commands for learning and remembering keyboard shortcuts.

    Re: Emacs recenter (C-l) equivalent for TM. Edit > Find > Jump to Selection (Cmd-J) is the closest I’ve found, though lacking prefix arguments that are often useful with Emacs’ recenter.

    What else have you found about TextMate that reminds you of Emacs or helps you get over it?

    Like the theme of your article, I’m still mostly in the “Emacs-isms I miss (or haven’t found yet) in TextMate” phase of usage. You and some of the followup comments covered a few things I’d noticed.

    To be continued!

    Hopefully soon? Maybe I’ll wait ‘til then to contribute instead of commenting more here. And I’m hoping to find other (ex-)Emacs users to collaborate with who’ve made or are making (at least attempted/attempting) a serious commitment to TM.


Use the following link to trackback from your own site: