From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#17756: indentation after declaring+initializing two arrays Date: Mon, 16 Jun 2014 21:31:44 +0000 Message-ID: <20140616213144.GB3433@acm.acm> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1402954659 2858 80.91.229.3 (16 Jun 2014 21:37:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Jun 2014 21:37:39 +0000 (UTC) Cc: 17756@debbugs.gnu.org To: Pietro Belotti Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 16 23:37:32 2014 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 1Wweao-0001gL-Gp for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Jun 2014 23:37:30 +0200 Original-Received: from localhost ([::1]:46378 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wweao-0006qq-4J for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Jun 2014 17:37:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wweac-0006ot-DS for bug-gnu-emacs@gnu.org; Mon, 16 Jun 2014 17:37:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WweaU-0002KB-RV for bug-gnu-emacs@gnu.org; Mon, 16 Jun 2014 17:37:18 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WweaM-0002HR-ME; Mon, 16 Jun 2014 17:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WweaM-0006kd-9A; Mon, 16 Jun 2014 17:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Mon, 16 Jun 2014 21:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17756 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 17756-submit@debbugs.gnu.org id=B17756.140295458025902 (code B ref 17756); Mon, 16 Jun 2014 21:37:02 +0000 Original-Received: (at 17756) by debbugs.gnu.org; 16 Jun 2014 21:36:20 +0000 Original-Received: from localhost ([127.0.0.1]:49712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WweZf-0006jh-Bf for submit@debbugs.gnu.org; Mon, 16 Jun 2014 17:36:19 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:43459 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WweZc-0006jU-3W for 17756@debbugs.gnu.org; Mon, 16 Jun 2014 17:36:17 -0400 Original-Received: (qmail 73508 invoked by uid 3782); 16 Jun 2014 21:36:14 -0000 Original-Received: from acm.muc.de (pD95194BE.dip0.t-ipconnect.de [217.81.148.190]) by colin.muc.de (tmda-ofmipd) with ESMTP; Mon, 16 Jun 2014 23:36:12 +0200 Original-Received: (qmail 4662 invoked by uid 1000); 16 Jun 2014 21:31:44 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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:90453 Archived-At: Hi, Pietro. On Thu, Jun 12, 2014 at 07:25:47PM +0000, Alan Mackenzie wrote: > Pietro Belotti wrote: > > Hello. I have a problem with Emacs (version: 23.4.1 > > (x86_64-pc-linux-gnu, GTK+ Version 2.24.10) of 2012-09-08 on trouble, > > modified by Debian [2 times]). A declaration is incorrectly indented > > when following one where two or more arrays are declared and > > initialized. The function foo() below has "char c = 'a';" > > over-indented, while the function bar() following it has the same > > declaration correctly indented. > > int foo () { > > int a [2] = {1,2}, > > b [2] = {3,4}; > > char c = 'a'; > > } > > This also happens if a newline is placed between "int" and "a [2]", > > but it does not happen if a and b are declared on the same line. Both > > M-x indent-region and moving the cursor and hitting TAB result in > > this. I could not find any related issue in the mailing list archive, > > is this expected behaviour? > No, it's a bug. What is happening is that C Mode has got confused by the > brace expression "{1,2}" into thinking that a statement ends after > "{1,2},", because close braces are usually ends of statements. Hence it > thinks that "b [2] ...." is the beginning of a statement. The next > statement "char c ..." is thus indented under the "b [2] ...". Incidentally, in that snippet, "b" wasn't getting fontified either. I've prepared a fix for this, but unfortunately, I couldn't test it on Emacs 23.4; I built that version, but it hung at 100% CPU usage at startup. Nevertheless, perhaps you could try out the following (untested on 23.4) patch (which _isn't_ valid for the trunk), and let me know whether it fixes the problem. Thanks! *** cc-engine.el~ 2012-01-11 12:35:01.000000000 +0000 --- cc-engine.el 2014-06-15 16:21:23.000000000 +0000 *************** *** 943,949 **** ((and (eq (char-after) ?{) ! (not (c-looking-at-inexpr-block lim nil t))) ;; Passed a block sexp. That's a boundary ;; alright. (point)) --- 943,952 ---- ((and (eq (char-after) ?{) ! (not (c-looking-at-inexpr-block lim nil t)) ! (save-excursion ! (c-backward-token-2 1 t nil) ! (not (looking-at "=\\([^=]\\|$\\)")))) ;; Passed a block sexp. That's a boundary ;; alright. (point)) *************** *** 8759,8765 **** (if (eq (point) (c-point 'boi)) (c-add-syntax 'brace-list-close (point)) (setq lim (c-most-enclosing-brace c-state-cache (point))) ! (c-beginning-of-statement-1 lim) (c-add-stmt-syntax 'brace-list-close nil t lim paren-state))) (t --- 8762,8768 ---- (if (eq (point) (c-point 'boi)) (c-add-syntax 'brace-list-close (point)) (setq lim (c-most-enclosing-brace c-state-cache (point))) ! (c-beginning-of-statement-1 lim nil nil t) (c-add-stmt-syntax 'brace-list-close nil t lim paren-state))) (t *** cc-fonts.el~ 2012-01-11 12:35:01.000000000 +0000 --- cc-fonts.el 2014-06-15 16:28:33.000000000 +0000 *************** *** 841,847 **** paren-depth id-face got-init c-last-identifier-range ! (separator-prop (if types 'c-decl-type-start 'c-decl-id-start))) (while (and pos --- 841,848 ---- paren-depth id-face got-init c-last-identifier-range ! (separator-prop (if types 'c-decl-type-start 'c-decl-id-start)) ! brackets-after-id) (while (and pos *************** *** 899,911 **** ;; Search syntactically to the end of the declarator (";", ;; ",", a closen paren, eob etc) or to the beginning of an ;; initializer or function prototype ("=" or "\\s\("). ! ;; Note that the open paren will match array specs in ! ;; square brackets, and we treat them as initializers too. ! (c-syntactic-re-search-forward ! "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t)) (setq next-pos (match-beginning 0) id-face (if (and (eq (char-after next-pos) ?\() (let (c-last-identifier-range) (save-excursion (goto-char next-pos) --- 900,923 ---- ;; Search syntactically to the end of the declarator (";", ;; ",", a closen paren, eob etc) or to the beginning of an ;; initializer or function prototype ("=" or "\\s\("). ! ;; Note that square brackets are now not also treated as ! ;; initializers, since this broke when there were also ! ;; initializing brace lists. ! (let (found) ! (while ! (and (setq found ! (c-syntactic-re-search-forward ! "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t)) ! (eq (char-before) ?\[)) ! (backward-char) ! (c-safe (c-forward-sexp 1)) ! (setq found nil) ! (setq brackets-after-id t)) ! found)) (setq next-pos (match-beginning 0) id-face (if (and (eq (char-after next-pos) ?\() + (not brackets-after-id) (let (c-last-identifier-range) (save-excursion (goto-char next-pos) > > Thanks, > > Pietro -- Alan Mackenzie (Nuremberg, Germany).