6

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?

Piers Cawley
  • 686
  • 6
  • 13

3 Answers3

6

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 Dreisbach
  • 7,732
  • 6
  • 29
  • 27
  • Mmm... wrap region's nice. Now, if I can just get it to work out how to restore the selection after doing the wrap. – Piers Cawley Sep 17 '08 at 10:24
  • 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. – EfForEffort Sep 17 '08 at 19:45
3

Try http://autopair.googlecode.com

joao
  • 3,517
  • 1
  • 31
  • 43
  • 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 Mar 31 '10 at 07:25
  • 1
    This answer also courtesy of "the same guy". :) – event_jr Feb 21 '12 at 13:21
0

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

Automatically closing braces in Emacs?

Emacs typeover skeleton-pair-insert-maybe

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

Community
  • 1
  • 1
Singletoned
  • 5,089
  • 3
  • 30
  • 32