From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sam Halliday Newsgroups: gmane.emacs.help Subject: Re: auto indenting code blocks Date: Sun, 14 Jun 2015 12:54:02 -0700 (PDT) Message-ID: <53817a9a-5fb3-4b68-9a0f-212f7c39f917@googlegroups.com> References: <43ca5eee-94a4-47f3-8b69-3af8a38227cd@googlegroups.com> <87616rlt63.fsf@web.de> <871thfi3uo.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1434311721 572 80.91.229.3 (14 Jun 2015 19:55:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Jun 2015 19:55:21 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 14 21:55:20 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z4E00-0002Ne-Ei for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Jun 2015 21:55:20 +0200 Original-Received: from localhost ([::1]:59455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4Dzz-0000UT-Ty for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Jun 2015 15:55:19 -0400 X-Received: by 10.182.46.227 with SMTP id y3mr33527712obm.7.1434311642262; Sun, 14 Jun 2015 12:54:02 -0700 (PDT) X-Received: by 10.140.28.98 with SMTP id 89mr87980qgy.0.1434311642223; Sun, 14 Jun 2015 12:54:02 -0700 (PDT) Original-Path: usenet.stanford.edu!h15no2713982igd.0!news-out.google.com!k20ni1739qgd.0!nntp.google.com!z60no1213691qgd.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=82.13.129.22; posting-account=kRukCAoAAAANs-vsVh9dFwo5kp5pwnPz Original-NNTP-Posting-Host: 82.13.129.22 User-Agent: G2/1.0 Injection-Date: Sun, 14 Jun 2015 19:54:02 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:212642 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104926 Archived-At: 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 > wrote: > > Yuri Khan 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.