Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to auto-complete parentheses or quotation marks in emacs?

I've used XCode and Netbeans, and I've noticed that they have a feature to automatically complete quotation marks or parentheses (and I assume that other IDEs often do this also). I don't know what the name of this feature is, but is there any way to do this in Emacs?

For example, when I type

printf("

I would like it to automatically input

printf("")

placing the cursor in between the quotation marks.

Thank you.

like image 458
beardc Avatar asked Oct 21 '10 12:10

beardc


2 Answers

The basic variant would be AutoPairs. The same effect but a little more sophisticated can also be achieved with YASnippet.

like image 140
Jacob Oscarson Avatar answered Nov 08 '22 23:11

Jacob Oscarson


If you type M-(, that will insert both a ( and a ), and leave point in between; if you then type M-), that will move point across the closing ). I use this all the time.

There is also a mode called "paredit" (available from http://mumble.net/~campbell/emacs/paredit.el) which does this sort of thing for quotes as well, and probably other stuff.

like image 32
offby1 Avatar answered Nov 09 '22 01:11

offby1