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#4289: 23.1; Incorrect indentation in C, following certain 'case' labels Date: Mon, 31 Aug 2009 20:05:38 +0000 Message-ID: <20090831200538.GA15906@muc.de> References: <87eiqupc8l.fsf@bigdeer.rsh.net> Reply-To: Alan Mackenzie , 4289@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1251750443 11257 80.91.229.12 (31 Aug 2009 20:27:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 31 Aug 2009 20:27:23 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org To: Benjamin Moody , 4289@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 31 22:27:16 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MiDT9-0003uK-Hn for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Aug 2009 22:27:16 +0200 Original-Received: from localhost ([127.0.0.1]:42477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiDT8-0007Hy-Pe for geb-bug-gnu-emacs@m.gmane.org; Mon, 31 Aug 2009 16:27:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MiDT2-0007H9-IB for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:27:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MiDSw-0007Cz-O0 for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:27:08 -0400 Original-Received: from [199.232.76.173] (port=60458 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MiDSw-0007CI-6H for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:27:02 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:43324) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MiDSu-0002V8-Kw for bug-gnu-emacs@gnu.org; Mon, 31 Aug 2009 16:27:01 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7VKQt1k020787; Mon, 31 Aug 2009 13:26:56 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n7VKA7GK017557; Mon, 31 Aug 2009 13:10:07 -0700 Resent-Date: Mon, 31 Aug 2009 13:10:07 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Alan Mackenzie Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs , owner@emacsbugs.donarmstrong.com 2Resent-Date: Mon, 31 Aug 2009 20:10:07 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4289 X-Emacs-PR-Package: emacs,cc-mode X-Emacs-PR-Keywords: Original-Received: via spool by 4289-submit@emacsbugs.donarmstrong.com id=B4289.125174895415367 (code B ref 4289); Mon, 31 Aug 2009 20:10:07 +0000 Original-Received: (at 4289) by emacsbugs.donarmstrong.com; 31 Aug 2009 20:02:34 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mail.muc.de (qmailr@colin.muc.de [193.149.48.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7VK2V20015256 for <4289@emacsbugs.donarmstrong.com>; Mon, 31 Aug 2009 13:02:33 -0700 Original-Received: (qmail 69724 invoked by uid 3782); 31 Aug 2009 20:02:29 -0000 Original-Received: from acm.muc.de (pD9E52A28.dip.t-dialin.net [217.229.42.40]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 31 Aug 2009 22:02:27 +0200 Original-Received: (qmail 16005 invoked by uid 1000); 31 Aug 2009 20:05:38 -0000 Content-Disposition: inline In-Reply-To: <87eiqupc8l.fsf@bigdeer.rsh.net> User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Mon, 31 Aug 2009 16:27:08 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:30689 Archived-At: Hi, Benjamin! On Sat, Aug 29, 2009 at 04:59:54PM -0400, Benjamin Moody wrote: > In Emacs 23.1, I've found an issue with the indentation rules for C > mode. In some circumstances, following a series of multiple labels, > the second and subsequent statements are not indented properly. For > example, in the following code: > void foo(int x) > { > switch (x) { > case 1: > case 2: > printf("aaa"); > break; > case '3': > case '4': > printf("bbb"); > break; > } > } > the second 'break' statement should be indented by 4 spaces, to align > with the 'printf'. Indeed it should. > This problem seems to appear when there are multiple labels (either > normal named labels, 'case' labels, or 'default' labels) in a row, > with no intervening statments, and either the first or the last such > label is a 'case' label with a character constant as its value. > This problem does NOT occur with Emacs 22.3. It does occur in C++ and > ObjC modes as well. It affects indentation using either TAB or M-x > indent-region. > A workaround is to place the character constant(s) in parentheses. Yuck! > This is obviously not a serious problem, ... I might disagree about that. > ... but it is a somewhat annoying one which would be nice to see fixed. OK. Would you please test the patch below, which I think fixes it. Once you've applied the patch, please rebuild the CC Mode files as follows: M-x byte-compile-file cc-langs.el M-x byte-compile-file cc-engine.el M-x byte-compile-file cc-mode.el (This is needed because cc-{engine,mode}.el use macros contained in cc-langs.el.) Then restart Emacs if necessary, then test your file. Thank you indeed for such a wonderfully clear, concise and helpful bug report! Index: cc-engine.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-engine.el,v retrieving revision 1.76 diff -c -r1.76 cc-engine.el *** cc-engine.el 29 Aug 2009 02:07:45 -0000 1.76 --- cc-engine.el 31 Aug 2009 19:55:19 -0000 *************** *** 1067,1074 **** (not (eq ret 'beginning)) (looking-at c-case-kwds-regexp)) (if (< after-case:-pos start) ! (setq pos after-case:-pos) ! (setq ret 'label))) ;; Skip over the unary operators that can start the statement. (while (progn --- 1067,1075 ---- (not (eq ret 'beginning)) (looking-at c-case-kwds-regexp)) (if (< after-case:-pos start) ! (setq pos after-case:-pos)) ! (if (eq ret 'same) ! (setq ret 'label))) ;; Skip over the unary operators that can start the statement. (while (progn Index: cc-langs.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-langs.el,v retrieving revision 1.67 diff -c -r1.67 cc-langs.el *** cc-langs.el 19 May 2009 22:35:07 -0000 1.67 --- cc-langs.el 31 Aug 2009 19:55:21 -0000 *************** *** 2885,2891 **** i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat ;; Don't allow string literals. ! "[\"']\\|" ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) --- 2885,2891 ---- i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat ;; Don't allow string literals. ! "\"\\|" ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) > Benjamin Moody -- Alan Mackenzie (Nuremberg, Germany)