From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Josh Newsgroups: gmane.emacs.bugs Subject: bug#15478: cc-mode does not obey electric-indent-mode Date: Mon, 7 Oct 2013 14:23:20 -0700 Message-ID: References: <20130929091017.GA3161@acm.acm> <20131002200737.GA3895@acm.acm> <20131003105600.GB3211@acm.acm> <20131005165034.GA2943@acm.acm> <20131007131122.GC3859@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1381181058 17018 80.91.229.3 (7 Oct 2013 21:24:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Oct 2013 21:24:18 +0000 (UTC) Cc: 15478@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 07 23:24:20 2013 Return-path: Envelope-to: geb-bug-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 1VTIHr-00026p-Lb for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Oct 2013 23:24:19 +0200 Original-Received: from localhost ([::1]:33544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTIHr-0007ij-6t for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Oct 2013 17:24:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTIHk-0007id-85 for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2013 17:24:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTIHf-0007d7-Ht for bug-gnu-emacs@gnu.org; Mon, 07 Oct 2013 17:24:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTIHa-0007cX-6g; Mon, 07 Oct 2013 17:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VTIHZ-0003FM-Qo; Mon, 07 Oct 2013 17:24:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Josh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Mon, 07 Oct 2013 21:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15478 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 15478-submit@debbugs.gnu.org id=B15478.138118103712464 (code B ref 15478); Mon, 07 Oct 2013 21:24:01 +0000 Original-Received: (at 15478) by debbugs.gnu.org; 7 Oct 2013 21:23:57 +0000 Original-Received: from localhost ([127.0.0.1]:32914 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VTIHT-0003Ew-7w for submit@debbugs.gnu.org; Mon, 07 Oct 2013 17:23:55 -0400 Original-Received: from mail-qc0-f172.google.com ([209.85.216.172]:60336) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VTIHP-0003En-ER for 15478@debbugs.gnu.org; Mon, 07 Oct 2013 17:23:52 -0400 Original-Received: by mail-qc0-f172.google.com with SMTP id l13so5346349qcy.3 for <15478@debbugs.gnu.org>; Mon, 07 Oct 2013 14:23:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-type; bh=DoNBth6JJc2W8QuOyk0ao31GgvPx85IcoyTZ+i1AKrA=; b=RRRD2PY/Hh4PWgdJcXPUkS3a2/KznSMuEOCxxFVA4pxbTRLlWySfRShDJRbezG/ODH JZbAmeX6YPZ0vQnGbwRfL5TFw3aKd0m8SbhRq6HfiwqIocCFXLPEd/68uuHQoGDb4eY4 FiExLWKqMsjXIsF3vhQA2vD0yoTvhrs+10p49tcFsVteF1PzRjP7xcudNcrNI+i8FyAk wl8yIEYXlf3BgTntitzIDRuCniWUPUCXMyEXpKXkdxDEvzyT0BjA9oMFB4fYG+sSkc+9 R2VjwLfoICGqA977IvuFhStxhrp0MEM8hFpVp7nPAykTFRe1icyX6PY/llChQhDaNiqv JYbg== X-Gm-Message-State: ALoCoQkKENTUjS/kIJivX0bNYon/dNrj3KrykdK65xSXNa6/Wv/hf2TUxdBFQf4I2QvWN0Hra52/ X-Received: by 10.224.67.3 with SMTP id p3mr5109122qai.98.1381181030951; Mon, 07 Oct 2013 14:23:50 -0700 (PDT) Original-Received: by 10.49.38.162 with HTTP; Mon, 7 Oct 2013 14:23:20 -0700 (PDT) In-Reply-To: <20131007131122.GC3859@acm.acm> X-Google-Sender-Auth: zv35N2CorqDjunKKR1vfEXMl8Oc X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:78997 Archived-At: On Mon, Oct 7, 2013 at 6:11 AM, Alan Mackenzie wrote: > On Sun, Oct 06, 2013 at 10:45:59AM -0700, Josh wrote: > > My previous question was based on a supposition (perhaps naive, as I'm > > not at all familiar with the CC Mode code) that its indentation > > functionality was either already centralized into a some "indent this > > line properly" function or that it would be desirable and feasible to > > make it so. If that were so, it seemed to me that such a function > > could be pressed into service as an electric-indent-function without > > too much trouble. > That could indeed be done, but the "too much trouble" would arise from > having to maintain separate versions of this code for the current Emacs, > and for Xemacs and historical Emacsen. > > Have a look at the code for `c-electric-brace' in cc-cmds.el. OK, I did. I saw what I take to be the embodiment of years of hard-won experience about how to implement this functionality correctly, and I fully agree that we could ill-afford to lose it. In hindsight I don't think I described the "centralized" `c-indent-this-line-properly' function I have in mind very well so let me try again, continuing with your example of braces. Start by factoring the indentation logic out of the current `c-electric-brace' implementation and call the extracted function `c-electric-brace-indent'. Call what's left `c-electric-brace*' and change its behavior to merely insert the brace and then call `c-indent-this-line-properly' with the inserted character as an argument. The latter function would then dispatch to the appropriate CC Mode indentation function, in this case the extracted `c-electric-brace-indent'. Here are the key bindings and call trees I had in mind: |--------+---------------------------------+--------------------------------| | | Current Emacs | XEmacs, older GNU Emacs | |--------+---------------------------------+--------------------------------| | {,} -> | self-insert-command | c-electric-brace* | |--------+---------------------------------+--------------------------------| | Call | electric-indent-post-self-[...] | c-electric-brace* | | Tree | `- c-indent-this-line-properly | `- c-indent-this-line-properly | | | `- c-electric-brace-indent | `- c-electric-brace-indent | |--------+---------------------------------+--------------------------------| In both cases, the same events (character insertion) trigger the same CC Mode indentation code extracted from the current implementation. I'm aware that such a scheme may be impractical for reasons unknown to me, but otherwise then at least for indentation triggered by character insertion the only maintenance burden I can see is that of the thin c-electric-brace* wrapper. > > (or c-force-electric-flag electric-layout-mode electric-indent-mode) > That's not going to gain anything, since `c-force-electric-flag' would > need to default to t to preserve existing behaviour. The need to preserve existing behavior is not a given. The above change would cause the (initial) enablement of electric behavior in CC Mode to be predicated on global electricity enablement, which is the subject of this bug. > > .... Even so, it would be a vast improvement for newbies who do not > > want this behavior. > > Yes, but it would be undesirable for those other newbies who do want > automatic indentation. "Newby" here means those unfamiliar with > `c-toggle-electric-state' and `electric-indent-mode'. Identifying the right set of defaults is important and likely to be an extensive discussion in itself, but one that should take place as part of some other bug. This bug is about the fact that CC Mode disregards configuration that is documented to be global.