Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can can I get emacs to insert closing braces automatically

I've just started using emacs, and there's one feature I'd really like, and searching around a bit was fruitless. I hope someone else has done this because I don't want to learn elisp just yet.

void foo()<cursor>

I would like typing an "{" to cause this to happen

void foo(){
    <cursor>
}

I would like this to only happen in cc-mode, and only at the end of a line when not in a string/comment/etc

The first thing that came to mind was rebinding "{" to do this always(I could figure out how to do this myself), but it would be hard to make it only happen at the right time.

any hints would be appreciated.

like image 814
Bwmat Avatar asked Sep 27 '10 04:09

Bwmat


Video Answer


1 Answers

on latest emacs you can use :

electric-pair-mode is an interactive compiled Lisp function.

(electric-pair-mode &optional ARG)

Automatically pair-up parens when inserting an open paren.

this is integrated in Emacs 24.1 (actually CVS)

like image 120
Chmouel Boudjnah Avatar answered Nov 23 '22 10:11

Chmouel Boudjnah