Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Electric braces

64 views
Skip to first unread message

Guido Van Hoecke

unread,
Sep 19, 2012, 1:11:55 PM9/19/12
to help-gn...@gnu.org
Hi,

When using 'electric braces' in Visual Studio, MonoDevelop and other
tools, I like the behaviour where the closing brace is auto-detected.

(In the example, I show the insertion point as a bar)
If I type

if (|

the screen shows

if (|)

I then key in my test expression, say isFalse (or whatever):

if (isFalse|)

At this point, Visual studio and MonoDevelop realise that the next ')'
key I hit, really represents the ')' which is already there. It does not
add an additional ')' :

if (isFalse)|

But in Emacs, currently using cperl, but also when using c#-mode, or
IIRC ruby-mode, emacs does add an additional ')' which leads to
following erroneous code:

if (isFalse)|)

I am pretty cinfident that Emacs can mimic the VS/MD behaviour. I just
did not find yet how to request it from good old Emacs.

Thanks in advance for any suggestions,




Guido

--
Expect a letter from a friend who will ask a favor of you.

http://vanhoecke.org ... and go2 places!

Константин Куликов

unread,
Sep 19, 2012, 1:17:41 PM9/19/12
to Guido Van Hoecke, help-gn...@gnu.org
google autopair.el

2012/9/19 Guido Van Hoecke <gui...@gmail.com>

Pascal J. Bourguignon

unread,
Sep 19, 2012, 1:33:03 PM9/19/12
to help-gn...@gnu.org
Guido Van Hoecke <gui...@gmail.com> writes:

> Hi,
>
> When using 'electric braces' in Visual Studio, MonoDevelop and other
> tools, I like the behaviour where the closing brace is auto-detected.
>
> (In the example, I show the insertion point as a bar)
> If I type
>
> if (|
>
> the screen shows
>
> if (|)
>
> I then key in my test expression, say isFalse (or whatever):
>
> if (isFalse|)
>
> At this point, Visual studio and MonoDevelop realise that the next ')'
> key I hit, really represents the ')' which is already there. It does not
> add an additional ')' :
>
> if (isFalse)|
>
> But in Emacs, currently using cperl, but also when using c#-mode, or
> IIRC ruby-mode, emacs does add an additional ')' which leads to
> following erroneous code:
>
> if (isFalse)|)
>
> I am pretty cinfident that Emacs can mimic the VS/MD behaviour. I just
> did not find yet how to request it from good old Emacs.
>
> Thanks in advance for any suggestions,

paredit-mode does that, but perhaps some more since it's for lisp
editing. You'll want to extract parts of it.

--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.


Dmitry Gutov

unread,
Sep 19, 2012, 2:22:21 PM9/19/12
to zxno...@gmail.com, help-gn...@gnu.org
Константин Куликов <zxno...@gmail.com> writes:

> google autopair.el

Why google? Here's the home page: http://code.google.com/p/autopair/

And yes, it's the most popular package for this purpose.

I especially like the newline behavior (the fourth bullet point).

Stefan Monnier

unread,
Sep 19, 2012, 11:47:20 PM9/19/12
to
> I am pretty cinfident that Emacs can mimic the VS/MD behaviour. I just
> did not find yet how to request it from good old Emacs.

The built-in electric-pair-mode does that.


Stefan

Guido Van Hoecke

unread,
Sep 20, 2012, 10:58:08 AM9/20/12
to Stefan Monnier, help-gn...@gnu.org
Hi Stefan, Pascal and Constantin
Thanks for your kind replies.

I tried the built-inelectric-pair-mode and it does what I want.

With kind regards,


Guido

--
Death is nature's way of saying `Howdy'.

Stefan Monnier

unread,
Sep 20, 2012, 1:38:43 PM9/20/12
to
> I tried the built-in electric-pair-mode and it does what I want.

I'm glad you like it,


Stefan

João Távora

unread,
Sep 21, 2012, 12:56:19 PM9/21/12
to Stefan Monnier, help-gn...@gnu.org
(originally forgot to cc: help-gn...@gnu.org)

I'd just like to add that autopair:

* is now hosted at github.com/capitaomorte/autopair
* out of the box, does a bit more than electric-pair-mode, like
deleting 0-width paren pairs when backspacing and helping to keep the
buffer balanced (for example typing 3 opening "{" consecutively makes
"{{{}}}" instead of electric pair's "{{{}".
* can be customized to behave differently in comments and strings,
pair characters, and more

I'm quite positively surprised how electric-pair-mode has evolved
though, but still find it awkward in how it sometimes pairs and
sometimes doesn't.

--
João Távora
0 new messages