all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lowell Gilbert <lgusenet@be-well.ilk.org>
To: help-gnu-emacs@gnu.org
Subject: Re: How to auto set the c style while editing C file?
Date: Wed, 26 May 2010 11:26:38 -0400	[thread overview]
Message-ID: <44r5ky8z0x.fsf@be-well.ilk.org> (raw)
In-Reply-To: 877hmryrsh.fsf@ymail.invalid

Water Lin <WaterLin@ymail.invalid> 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.


       reply	other threads:[~2010-05-26 15:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <877hmryrsh.fsf@ymail.invalid>
2010-05-26 15:26 ` Lowell Gilbert [this message]
2010-05-27  1:40   ` How to auto set the c style while editing C file? Water Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44r5ky8z0x.fsf@be-well.ilk.org \
    --to=lgusenet@be-well.ilk.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.