From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: c preprocessor and indent problem in c-mode? Date: Mon, 26 Jan 2009 09:00:47 +0000 Message-ID: <20090126090047.GA1417@muc.de> References: <035566ec-3070-441e-8040-6f44c5c0d96c@p36g2000prp.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1232998113 30069 80.91.229.12 (26 Jan 2009 19:28:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 26 Jan 2009 19:28:33 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: YOUNG Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 26 20:29:46 2009 Return-path: Envelope-to: geh-help-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 1LRX9P-0000c9-Ed for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Jan 2009 20:29:39 +0100 Original-Received: from localhost ([127.0.0.1]:39725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LRX87-0005wV-6q for geh-help-gnu-emacs@m.gmane.org; Mon, 26 Jan 2009 14:28:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LRVsu-0006hk-Qw for help-gnu-emacs@gnu.org; Mon, 26 Jan 2009 13:08:32 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LRVss-0006ga-Bg for help-gnu-emacs@gnu.org; Mon, 26 Jan 2009 13:08:32 -0500 Original-Received: from [199.232.76.173] (port=51737 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LRVsr-0006gT-Qh for help-gnu-emacs@gnu.org; Mon, 26 Jan 2009 13:08:29 -0500 Original-Received: from mx20.gnu.org ([199.232.41.8]:52489) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LRVJX-0006oG-KO for help-gnu-emacs@gnu.org; Mon, 26 Jan 2009 12:32:00 -0500 Original-Received: from colin.muc.de ([193.149.48.1] helo=mail.muc.de) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LRN4A-0002fd-IS for help-gnu-emacs@gnu.org; Mon, 26 Jan 2009 03:43:34 -0500 Original-Received: (qmail 42825 invoked by uid 3782); 26 Jan 2009 08:42:02 -0000 Original-Received: from acm.muc.de (pD9E23FB9.dip.t-dialin.net [217.226.63.185]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Mon, 26 Jan 2009 09:42:00 +0100 Original-Received: (qmail 1708 invoked by uid 1000); 26 Jan 2009 09:00:47 -0000 Content-Disposition: inline In-Reply-To: <035566ec-3070-441e-8040-6f44c5c0d96c@p36g2000prp.googlegroups.com> User-Agent: Mutt/1.5.9i X-Delivery-Agent: TMDA/1.1.5 (Fettercairn) X-Primary-Address: acm@muc.de X-detected-kernel: by mx20.gnu.org: FreeBSD 4.6-4.9 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61662 Archived-At: Hi, there, On Sun, Jan 25, 2009 at 04:46:38PM -0800, YOUNG wrote: > Hi, > If there is a following code, emacs does not present indent correctly. > #incude > int main(void) { > int a = 10; > #ifdef AAA > if (a == 10) { <====================== A > printf("a:%d\n", a); > #else > if (b == 10) { <====================== B > printf("b=10\n"); > #endif > } > #endif > } > If the curly brace is not closed before the preprocessor, emacs seems > to confuse to make indent. Yes. > Is there anyone who know this problem and how to resolve? Yes. CC Mode doesn't take account of the #ifdef and #else when parsing braces. So it looks like the brace on line B is nested within the brace on line A. This is a longstanding bug, which needs fundamental work in CC Mode (and possibly the Emacs core) to fix. It may get fixed in the medium future. Sorry! A reasonable workaround, if the project you're working on will let you, is to keep braces in #ifdefs (and #defines) balanced. You could thus write this instead: #ifdef AAA if (a == 10) { printf("a:%d\n", a); } #else if (b == 10) { printf("b=10\n"); } #endif -- Alan Mackenzie (Nuremberg, Germany).