From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: auto indenting code blocks Date: Sun, 14 Jun 2015 11:24:29 +0600 Message-ID: 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1434259509 3802 80.91.229.3 (14 Jun 2015 05:25:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Jun 2015 05:25:09 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 14 07:25:09 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 1Z40Pp-0001up-VQ for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Jun 2015 07:25:06 +0200 Original-Received: from localhost ([::1]:57732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z40Pp-0006GQ-4N for geh-help-gnu-emacs@m.gmane.org; Sun, 14 Jun 2015 01:25:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z40Pe-0006GL-GV for help-gnu-emacs@gnu.org; Sun, 14 Jun 2015 01:24:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z40Pb-0001kX-6C for help-gnu-emacs@gnu.org; Sun, 14 Jun 2015 01:24:54 -0400 Original-Received: from mail-la0-x22c.google.com ([2a00:1450:4010:c03::22c]:33023) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z40Pa-0001kS-UZ for help-gnu-emacs@gnu.org; Sun, 14 Jun 2015 01:24:51 -0400 Original-Received: by lacdj3 with SMTP id dj3so20537523lac.0 for ; Sat, 13 Jun 2015 22:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=X/U4M603aZzS85k9hpWZZGmJ+7l1oeyqc+sFa++ZJfU=; b=xXAdddQYFNTHxycjTxPdAnq9DZ9zLhudaqloTKuWEDbDUpqyMHAqrNH+/eekLWbEbX 3LILqunu7VaYXUmEvCy/kel1r47/W3BiBUhNwzNfkNDg6wjSXeKr8iqf8Im8Q3/hAUXu Mwy/mZZMAiNQ+j/BhBBQ+QNT9v0MAcwxhn5C/coGanUEuSJomXgkoXGi90XNrtLDhOt6 9qEWO6VhEHbuRtH6J+1LZS2PhRuLSjQXj+ejAtiYZDTu/lSBSQLWfpShjizQT+TW32RQ pSj+izfL0Y5VXj3CB/I8VFQdnX0ZXjeiljjH60PhH5mYwwC41e5lZCETyGRwCRxgHHU7 OEUw== X-Received: by 10.152.21.168 with SMTP id w8mr21316696lae.22.1434259490075; Sat, 13 Jun 2015 22:24:50 -0700 (PDT) Original-Received: by 10.25.43.65 with HTTP; Sat, 13 Jun 2015 22:24:29 -0700 (PDT) In-Reply-To: <871thfi3uo.fsf@web.de> X-Google-Sender-Auth: 2PQLcW-5sr2Gi7nynA6KaJHXIHo X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22c 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:104917 Archived-At: 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=E2=80=99s a smartparens bug. Its job in this context is= to add a matching closing brace as soon as an opening brace is inserted. It=E2=80=99s 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=E2=80=99s possible we are overlooking some part of smartparens=E2= =80=99 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-h= ooks 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-h= ooks =3D=3D=3D (sp-local-pair 'c++-mode "{" nil :post-handlers '(("||\n[i]" "RET"))) =3D=3D=3D Sam, you might also like this: =3D=3D=3D (sp-local-pair 'c++-mode "{" nil :post-handlers '(("||\n[i]" "RET") ("| " "SPC"))) =3D=3D=3D (substitute your major mode). I think I=E2=80=99ll take it for a drive. Michael, thank you for encouragin= g me to figure this out.