all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sam Halliday <sam.halliday@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: auto indenting code blocks
Date: Sun, 14 Jun 2015 12:54:02 -0700 (PDT)	[thread overview]
Message-ID: <53817a9a-5fb3-4b68-9a0f-212f7c39f917@googlegroups.com> (raw)
In-Reply-To: <mailman.4973.1434259496.904.help-gnu-emacs@gnu.org>

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.



  parent reply	other threads:[~2015-06-14 19:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-13 10:40 auto indenting code blocks Sam Halliday
2015-06-13 11:25 ` Yuri Khan
2015-06-13 11:55   ` Michael Heerdegen
2015-06-13 13:14     ` Yuri Khan
2015-06-13 23:30       ` Michael Heerdegen
2015-06-14  5:24         ` Yuri Khan
     [not found]         ` <mailman.4973.1434259496.904.help-gnu-emacs@gnu.org>
2015-06-14 19:54           ` Sam Halliday [this message]
2015-06-14 19:59           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53817a9a-5fb3-4b68-9a0f-212f7c39f917@googlegroups.com \
    --to=sam.halliday@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.