help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: auto indenting code blocks


From: Sam Halliday
Subject: Re: auto indenting code blocks
Date: Sun, 14 Jun 2015 12:54:02 -0700 (PDT)
User-agent: G2/1.0

Yuri, this is *exactly* what I wanted... thank you so much for figuring it out 
:-D

On Sunday, 14 June 2015 06:24:58 UTC+1, Yuri Khan  wrote:
> On Sun, Jun 14, 2015 at 5:30 AM, Michael Heerdegen
> <michael_heerdegen@web.de> wrote:
> > Yuri Khan <yuri.v.khan@gmail.com> writes:
> >
> >> > Shouldn't `electric-indent-mode' be able to do this?
> >> Maybe it should, but it does not for me.
> >
> >> If I forgo smartparens, then electric-indent-mode does indeed yield
> >> the desired sequence:
> >
> > Then I think someone should make a bug report at the smartparens site
> > please:
> >
> >   https://github.com/Fuco1/smartparens
> 
> I do not believe it's a smartparens bug. Its job in this context is to
> add a matching closing brace as soon as an opening brace is inserted.
> 
> It's not an electric-indent-mode bug, either. When a line break is
> inserted immediately before a closing brace, it reindents the closing
> brace according to the mode and style.
> 
> What Sam and I want, however, is, with a single Enter keypress, to
> insert *two* line breaks, position the point between them, and indent
> everything nicely. This is just a piece of unimplemented
> functionality, and we implement it in slightly different but similar
> ways. It's possible we are overlooking some part of smartparens'
> functionality, hence this thread.
> 
> Actually, the smartparens documentation mentions a facility for adding
> hooks on pair insertion:
> 
> https://github.com/Fuco1/smartparens/wiki/Permissions#pre-and-post-action-hooks
> 
> One of its examples specifically adds two line breaks, positions point
> in between, and reindents, but this happens immediately after
> inserting a brace, making it inconvenient to insert one-liners.
> 
> The final example in the same section adds a hook that runs after a
> pair of braces is inserted *and* RET is pressed as the immediate next
> action. Which is pretty close to what I want but I think I prefer that
> it happen every time I press Enter while in an empty pair of braces,
> not only when said pair is newly inserted.
> 
> The next section describes a more concise syntax for such insertions:
> 
> https://github.com/Fuco1/smartparens/wiki/Permissions#pre-and-post-action-hooks
> 
> ===
> (sp-local-pair 'c++-mode "{" nil :post-handlers '(("||\n[i]" "RET")))
> ===
> 
> Sam, you might also like this:
> 
> ===
> (sp-local-pair 'c++-mode "{" nil :post-handlers '(("||\n[i]" "RET")
> ("| " "SPC")))
> ===
> 
> (substitute your major mode).
> 
> 
> I think I'll take it for a drive. Michael, thank you for encouraging
> me to figure this out.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]