From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lowell Gilbert Newsgroups: gmane.emacs.help Subject: Re: How to auto set the c style while editing C file? Date: Wed, 26 May 2010 11:26:38 -0400 Message-ID: <44r5ky8z0x.fsf@be-well.ilk.org> References: <877hmryrsh.fsf@ymail.invalid> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291823225 31273 80.91.229.12 (8 Dec 2010 15:47:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 8 Dec 2010 15:47:05 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 08 16:47:01 2010 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.69) (envelope-from ) id 1PQMEO-0005tV-9p for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 16:47:00 +0100 Original-Received: from localhost ([127.0.0.1]:52537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQMEN-0003Xd-G4 for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 10:46:59 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail Original-NNTP-Posting-Date: Wed, 26 May 2010 10:26:39 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) Cancel-Lock: sha1:FwgEdJOKTXgJ9dp2tQb+FnwT/rU= Original-Lines: 39 X-Usenet-Provider: http://www.giganews.com Original-NNTP-Posting-Host: 66.92.78.145 Original-X-Trace: sv3-Ot35EiJJcwJRgZpAm0+vDF+mM9/nv3mu2n6dO7RWvN6WJnaoD2v2yHeIuJNH7ptUMBiEZlbH3IkDuCS!KnmhkeOetvEs4Xkbxz27BXd9OVyRqoqmDtWe28wr4hciomsWE6X1XJsulCnxhDCPUpmv7NJUn0yp!2N+JMYkf7Q== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: usenet.stanford.edu gnu.emacs.help:178430 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:75555 Archived-At: Water Lin writes: > I am using Emacs to edit for C/C++ code in some cases. > > But the default gnu style is not fit my requirement. > > 1. > > I want to use stroustrup style as default. > > I tried to use following code in my .emacs: > ----------- > (c-set-style "stroustrup") > > But Emacs will remind me that some files are not in C-mode. > > How can I enable stroustrup style automatically while I am using > c-mode/c++-mode. (add-hook 'c-mode-common-hook (function (lambda () (c-set-style "gnu")))) ; gnu is default > 2. > > Another question, after I input one line code and use C-i to indent the > code, Emacs will insert a TAB for me which is TAB-width 8. > > I want to set TAB-width as 4 and in this case I don't want Emacs to > inset TAB automatically but insert 4 blackspaces instead. Also in c-mode-common-hook: (setq indent-tabs-mode nil) and probably (setq c-basic-offset 4) See the c-mode manual for more details on how this works and what else you can set.