From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Water Lin Newsgroups: gmane.emacs.help Subject: Re: How to auto set the c style while editing C file? Date: Thu, 27 May 2010 09:40:28 +0800 Organization: A poorly-installed InterNetNews site Message-ID: <87zkzm3ywj.fsf@ymail.invalid> References: <877hmryrsh.fsf@ymail.invalid> <44r5ky8z0x.fsf@be-well.ilk.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1291951270 26903 80.91.229.12 (10 Dec 2010 03:21:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Dec 2010 03:21:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 10 04:21:06 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 1PQtXX-0003mz-8d for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Dec 2010 04:21:05 +0100 Original-Received: from localhost ([127.0.0.1]:41145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQtXP-00028Q-Ul for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 22:20:52 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!newsgate.cuhk.edu.hk!www.shinco.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 53 Original-NNTP-Posting-Host: 58.62.82.132 Original-X-Trace: www.shinco.com 1274924428 23781 58.62.82.132 (27 May 2010 01:40:28 GMT) Original-X-Complaints-To: news@www.shinco.com Original-NNTP-Posting-Date: Thu, 27 May 2010 01:40:28 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:yi1Xy2OybKlEBlUtbkfq64PS6tI= Original-Xref: usenet.stanford.edu gnu.emacs.help:178437 X-Mailman-Approved-At: Thu, 09 Dec 2010 20:23:35 -0500 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:77263 Archived-At: Lowell Gilbert writes: > 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. Ok. Thanks, I am studying elisp right now. I will check the manual for detail. Thanks Water Lin -- Water Lin's notes and pencils: http://en.waterlin.org Email: WaterLin@ymail.com