tags:

views:

316

answers:

3

In textmate, when there's a current selection, I hit the " key and the selection gets surrounded by quotes. The same thing happens with other balanced characters like (, {, [ and '.

Am I missing something obvious in Emacs configuration that would enable similar behaviour when using transient mark mode, or do I need to break out elisp and write something?

+5  A: 

wrap-region.el from this guy's blog post will do what you're looking for.

Paredit will complete the TextMate-style quoting. When you type one part of a matched pair (quotes, brackets, parentheses, etc), the second will be inserted and the insertion point is moved between them, much like TextMate.

Clinton R. Nixon
Mmm... wrap region's nice. Now, if I can just get it to work out how to restore the selection after doing the wrap.
pdcawley
The skeleton-pair mechanism mentioned in the post preamble is quite general and is built-in to emacs -- no need to fetch wrap-region for new emacs installs or worry about wrap-region's compatibility.
Denis Bueno
+2  A: 

Try http://autopair.googlecode.com

Joao Tavora
I'll second autopair. I've been using it for a while now and it's near perfect replacement. Yasnippet by the same guy is also a perfect replacement for Textmate snippets.
Singletoned
A: 

You should check out these older, very similar, questions:

http://stackoverflow.com/questions/1023770/automatically-closing-braces-in-emacs/1024531#1024531

http://stackoverflow.com/questions/848647/emacs-typeover-skeleton-pair-insert-maybe/849218#849218

Although the correct answer is Joao's above; I'm about to go and change my answer to those questions, to point to autopair.

Singletoned