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: Indentation for "{" and "}" Date: Sun, 29 Jul 2007 18:08:24 +0000 Message-ID: <20070729180824.GC1955@muc.de> References: <1185729825.415156.320980@g4g2000hsf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1185732507 8423 80.91.229.12 (29 Jul 2007 18:08:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 29 Jul 2007 18:08:27 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Rafal Kurcz Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 29 20:08:21 2007 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 1IFDBk-0005mx-2x for geh-help-gnu-emacs@m.gmane.org; Sun, 29 Jul 2007 20:08:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IFDBj-0005VM-Jh for geh-help-gnu-emacs@m.gmane.org; Sun, 29 Jul 2007 14:08:19 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IFDBG-0005Or-KR for help-gnu-emacs@gnu.org; Sun, 29 Jul 2007 14:07:50 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IFDBF-0005OH-Ee for help-gnu-emacs@gnu.org; Sun, 29 Jul 2007 14:07:50 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IFDBF-0005OB-8i for help-gnu-emacs@gnu.org; Sun, 29 Jul 2007 14:07:49 -0400 Original-Received: from colin.muc.de ([193.149.48.1] helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IFDBE-0005Yh-Lj for help-gnu-emacs@gnu.org; Sun, 29 Jul 2007 14:07:49 -0400 Original-Received: (qmail 39061 invoked by uid 3782); 29 Jul 2007 18:07:46 -0000 Original-Received: from acm.muc.de (p57B1DF05.dip.t-dialin.net [87.177.223.5]) by colin2.muc.de (tmda-ofmipd) with ESMTP; Sun, 29 Jul 2007 20:07:44 +0200 Original-Received: (qmail 10476 invoked by uid 1000); 29 Jul 2007 18:08:24 -0000 Content-Disposition: inline In-Reply-To: <1185729825.415156.320980@g4g2000hsf.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: FreeBSD 4.6-4.9 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:46166 Archived-At: Hi, Rafal! On Sun, Jul 29, 2007 at 10:23:45AM -0700, Rafal Kurcz wrote: > Hello > I want my C++ code to look as follows: > void function() > { > printf ( "hello" ); > } > and not look as follows: > void function() > { > pirntf ( "hello" ); > } The code above is formatted in "gnu" style, the default for the GNU project and the default within Emacs. No, I don't like it either. ;-) What you need to do is to change that style to one you like better (or, in the extreme, to create your own style which is perfect.) Put the following line in your .emacs, fairly early on (before any C files can be loaded): (setq c-default-style "bsd") This is described in the CC Mode manual on the page "Getting Started". If "bsd" isn't quite your style, pick one of those listed on the page "Built-in Styles". It wouldn't do any harm to read the general stuff about styles in the manual. ;-) You might find C-c . (that's "Control-C dot") useful for trying out styles. > I added the following setting to my ~/.emacs file: > (global-set-key "\C-m" 'newline-and-indent) > It works fine for all lines but "{". > How to tell emacs not to indent the lines with "{" and "}" That's got nothing to do with your "{ problem" (see above). As a matter of interest, you might find 'c-context-line-break a better binding for in C Mode, since this does the Right Thing inside comments and macros too. This is also described in the CC Manual page "Getting Started", but basically if you want this binding, put the following into your .emacs early on: (defun my-make-CR-do-indent () (define-key c-mode-base-map "\C-m" 'c-context-line-break)) (add-hook 'c-initialization-hook 'my-make-CR-do-indent) > Thanks for help No problem! Have fun! -- Alan Mackenzie (Ittersbach, Germany).