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: auto-newline before opening brace following "if", "else" and "for" Date: Sun, 23 Oct 2005 09:36:31 +0000 Organization: muc.de e.V. -- private internet access Message-ID: <0jlfjd.jb.ln@acm.acm> References: <1129702752.669786.195580@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1130066423 332 80.91.229.2 (23 Oct 2005 11:20:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 23 Oct 2005 11:20:23 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 23 13:20:22 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ETdtV-00007y-ID for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Oct 2005 13:20:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ETdtQ-00038a-3q for geh-help-gnu-emacs@m.gmane.org; Sun, 23 Oct 2005 07:20:00 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer.de.kpn-eurorings.net!newsfeed.freenet.de!news.space.net!news.muc.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-NNTP-Posting-Host: acm.muc.de Original-X-Trace: marvin.muc.de 1130060208 35446 193.149.49.134 (23 Oct 2005 09:36:48 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: 23 Oct 2005 09:36:48 GMT User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686)) Original-Xref: shelby.stanford.edu gnu.emacs.help:134904 Original-To: help-gnu-emacs@gnu.org 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:30489 Archived-At: ozark wrote on 18 Oct 2005 23:19:12 -0700: > I'm using C++-mode, with auto-newline turned on ("C++/ah Abbrev", it > shows). > c-set-style is set to gnu. I'm assuming here you've got CC Mode 5.28 (M-x c-version). > A newline is automatically inserted before and after an opening brace > if it follows a function name. However, when the brace is after an "if" > or an "else" or a "for", it places the brace on the same line and only > inserts a newline after it, i.e, it doesn't insert the newline before > the brace. > Is this default behaviour? How do I change it? This is a bug in CC Mode 5.28, which is still present in the latest released version (5.30.10). :-( Thanks for drawing it to our attention! The variable concerned is `c-hanging-braces-alist'. This is a "style variable", a buffer local variable which goes through all the contortions of CC Mode's style system for its initalisation. Because this variable is not explicitly specified in the "gnu" style, it is inheriting its value from the "user" style. You can see this value by doing C-h v c-hanging-brace-alist from your C Mode buffer. It will give this value: ((brace-list-open) (brace-entry-open) (substatement-open after) <========================== (block-close . c-snug-do-while) (extern-lang-open after) (inexpr-class-open after) (inexpr-class-close before)) The substatement-open entry is the problem. It should read (substatement-open . (before after)), (or, alternatively be absent, since before + after is the default). I suggest you work around this bug by setting c-hanging-braces-alist in a hook function. Put this (or something like it) into your .emacs: (defun oz-c-mode-common-hook () (setq c-hanging-braces-alist '((brace-list-open) (brace-entry-open) (substatement-open before after) ; <============ (block-close . c-snug-do-while) (extern-lang-open after) (inexpr-class-open after) (inexpr-class-close before)))) (add-hook 'c-mode-common-hook 'oz-c-mode-common-hook) -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a").