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: Sat, 13 Jun 2015 17:25:22 +0600 Message-ID: References: <43ca5eee-94a4-47f3-8b69-3af8a38227cd@googlegroups.com> 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 1434194769 5492 80.91.229.3 (13 Jun 2015 11:26:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Jun 2015 11:26:09 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Sam Halliday Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jun 13 13:26: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 1Z3jZg-0001OK-GM for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Jun 2015 13:26:08 +0200 Original-Received: from localhost ([::1]:55547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3jZf-0007rJ-DN for geh-help-gnu-emacs@m.gmane.org; Sat, 13 Jun 2015 07:26:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3jZL-0007qy-1s for help-gnu-emacs@gnu.org; Sat, 13 Jun 2015 07:25:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3jZJ-0000If-OC for help-gnu-emacs@gnu.org; Sat, 13 Jun 2015 07:25:46 -0400 Original-Received: from mail-la0-x22e.google.com ([2a00:1450:4010:c03::22e]:36148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3jZJ-0000IE-Cx for help-gnu-emacs@gnu.org; Sat, 13 Jun 2015 07:25:45 -0400 Original-Received: by lacny3 with SMTP id ny3so13409217lac.3 for ; Sat, 13 Jun 2015 04:25:43 -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=bOonolI4dzfcnx+EAqlZZS4Id9q4lDnwHiPggoni3gM=; b=XLLCTyPiCumbEJDDjrbMon1iCczqtNebOfoBRMcjpMcjIKF2RmHTFMf0GwZXxBockO DnUDQXCUyz3mlsN1ecJhTwfKOV9yKLwbgh5NwsNnK0xO6XxucVRsDfq8g/kwRwWqw1AD lh8RndwnaudmPOmqOri9qtsokLG4478CvtYcB4k4r/7UFBI586s8YdZ37LgVWSJPTWpw tzakNrTMAiOdJ5hYRcwp9D0Z38Hfgnuux9asy1jtbtwU5oBA1REGyEtuzxfacdrTgRY2 VQ0ja7QyPf69WKk/jsn0FltrY7AfEnm34s5tPQYQeOVCjv2ERwYDhhmMtaTJ6RIJxfmV fOMQ== X-Received: by 10.112.147.201 with SMTP id tm9mr19163247lbb.40.1434194743568; Sat, 13 Jun 2015 04:25:43 -0700 (PDT) Original-Received: by 10.25.43.65 with HTTP; Sat, 13 Jun 2015 04:25:22 -0700 (PDT) In-Reply-To: <43ca5eee-94a4-47f3-8b69-3af8a38227cd@googlegroups.com> X-Google-Sender-Auth: k4Rk1vCQjPIpO9uT6U8xSbwXxR0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22e 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:104911 Archived-At: On Sat, Jun 13, 2015 at 4:40 PM, Sam Halliday wrot= e: > I find it extremely convenient when writing Scala code (and this may be r= elevant in all c-mode derivations) to be able to have my code blocks automa= tically expanded. > > I have smart-parens installed, so when I type `{' the closing brace is pl= aced after point. > > But often I intend to write a multi-line block of code (this may well be = the norm in C and C++) and when I type newline I expect the second brace to= be moved down a line, indented, and the point placed, indented, in the mid= dle. I am solving this for C++ with the following ugly hack (BTW thanks for pointing out =E2=80=9Clooking-back=E2=80=9D): =3D=3D=3D (defun yk-electric-ret () (interactive) (if (and (looking-at "\}") (looking-back "\{"))) (progn (newline-and-indent) (save-excursion (newline-and-indent)) (indent-according-to-mode)) (newline-and-indent))) (defun yk-braces-keys () (local-set-key (kbd "RET") 'yk-electric-ret)) (add-hook 'c-mode-common-hook 'yk-braces-keys) =3D=3D=3D It is essentially equivalent to yours except that I prefer rebinding a single key to watching for all buffer changes. > I have cooked up a little post-self-insert-hook (see bottom of mail) but = it feels like I'm inventing some form of wheel. > > 1. is there an existing preferred way to do what my scala-block-indent = is trying to do? > 2. is there an easier way (perhaps via smart-parens) to achieve what my= scala-block-pad is doing, but at the point when the closing brace is inser= ted? I am also interested in answers to the above. Additionally, it would be nice to be able to select a multi-line region (def: a region that contains at least one line break), press =E2=80=9C{=E2=80=9D and have it automatically enclose the region in a pair = of braces, add a line break immediately after the opening brace and another one before the closing brace, and re-indent all affected lines according to mode and style. (I could probably compose a function to that effect and bind it to =E2=80=9C{=E2=80=9D instead of c-electric-brace or self-inse= rt-command, but that looks boring :])