What Makes Emacs Unique, Laundry-list Style

What really makes Emacs unique is the fact that it is a text editor with an embedded Turing-complete programming language. It’s infinitely customisable, and so allows you to arrange it according to what makes you personally productive.

But this post is not about philosophy. I’m dedicating this post to a laundry list of features that make Emacs better than any text editor/IDE/administration tool out there. (Some of them can be found in the Emacs guided tour.) I’ll try keep this post updated as I think of more features.

    Update 09 Jul 2007:

  • Regular expression builder
  • As you type a regular expression, every matching substring in the current buffer gets highlighted, and each submatch of the regular expression is highlighted in a different color. To use: M-x re-builder.

  • Keyboard macros
  • These allow the recording of a sequence of keystrokes to be replayed later. Anything possible to do in Emacs is possible through the keyboard, so this feature is quite powerful. It’s especially useful for tedious reformatting tasks.

    To use: C-x (, perform the actions you want to record, then C-x ) to stop. To run the keyboard macro at any time, use C-x e.

  • Unloseable undo
  • In any editor I’ve ever used, if you Undo several times, then type some, the stuff you undid cannot be redone. That portion of the undo history is lost. In Emacs, this is not the case: it is always possible to get back to any previous state of the buffer of text.

  • Interactive search-and-replace across directories
  • Say you need to rename most occurrences of a pattern, but not some. You won’t be able to use a perl -pi or find+sed since you need to exclude certain occurrences. What you need is an interactive process that lets you look at each match, and decide whether to replace.

    To use: look here.

Update 28 Jun 2008: I recently ran across a top ten list of emacs features. It’s quite useful.

Configuring Emacs for Gmail’s SMTP over SSL

When I finally convinced emacs to send mail with Gmail it was only after I had visited 6 or 7 websites on the topic, and inferred the solution. I’m posting here in hopes that at least one resource has all the information in one place. The task is to get Emacs to send mail using your Gmail account, over SSL.

Install starttls (gnutls)

According to Fink, starttls is a “simple wrapper program for STARTTLS protocol”, which is what implements SMTP-over-SSL. This step was the neglected one of all the blog entries I read on this topic. Even the emacs error messages given when attempting to send email without starttls available don’t indicate that it’s necessary or even missing. I had to poke around smtpmail.el to find out that such a program even existed.

Update 16 Jan 2008: As mentioned in the comments, installing gnutls also works. Update 09 Dec 2008: You may also need to customise the variable starttls-use-gnutls (loaded by the starttls package); for example:

(setq starttls-use-gnutls t)

Configure emacs

I eventually settled on the following settings for my .emacs:

(setq send-mail-function 'smtpmail-send-it
      message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials
      '(("smtp.gmail.com" 587 nil nil))
      smtpmail-auth-credentials
      (expand-file-name "~/.authinfo")
      smtpmail-default-smtp-server "smtp.gmail.com"
      smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      smtpmail-debug-info t)
(require 'smtpmail)

The smtpmail package is included in emacs 22. I’m not sure if it is included with any earlier version.

The file .authinfo is in netrc format. It’s for storing your authentication information. Here are some quick-start directions:

  1. Create an the file .authinfo in your home directory.
  2. Insert the following:
    machine smtp.gmail.com login [your name]@gmail.com password [your actual password]
    
  3. Set its permissions so only your user can read and write it. I did this with:
    chmod go-rwx .authinfo
    chmod u+rw .authinfo
    

Now, you should be able to run emacs and test it out by composing an email with C-x m, and sending with C-c C-c. Please feel free to post a comment if you have problems. And be sure to set the variable smtpmail-debug-verb to t while you’re debugging: it makes the *Messages* buffer include much more useful information.

Update 20 Jul 2007: Removed newlines in suggested .authinfo contents; I think it doesn’t parse correctly, at least under certain conditions.

Update 13 Dec 2008: Reworked the configuration so it always uses .authinfo — apparently Google doesn’t like it any other way. This came about because I tried using the non-.authinfo config on my machine, and Gmail kept rejecting mail to send. As soon as I started using .authinfo, it worked.