[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customizing tab indentation width

From: Alan Mackenzie
Subject: Re: Customizing tab indentation width
Date: Mon, 22 Sep 2003 08:51:35 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Sona <address@hidden> wrote on Sun, 21 Sep 2003 01:13:12 +1000:
> Hi,

> I want to set the default tab indetation width in emacs to be 2 spaces.
> I set this in the tab-with variable and also in the standard indent
> variable but it's not working. For example, if I type the following:

> if (someVariable == true) {
>      doSomething();
> }

> it indents doSomething() to 4 spaces.. I need this to be 2 spaces only.
> How can I do this? Thanks

Which language mode are you talking about?  It looks like C or C++, so
I'll assume it's C.  If it's C++, make the appropriate alterations to
what follows.

The Emacs variable which controls the indentation is c-basic-offset, so
you need to set this to 2.  However, each time you open a new C Mode
buffer, the setup code sets a "buffer-local" copy of this variable to 4.

So you need to put this setting into a "hook function", this being a
function which gets run every time you open a new C Mode buffer.
Specifically, put something like the following into your .emacs:

(defun my-c-mode-hook ()
  (setq c-basic-offset 2))
(add-hook 'c-mode-hook 'my-c-mode-hook)

The first two of these lines define a function to do what you need.  The
last line puts in into a list of functions to call at setup time.

For further details, see the CC Mode info pages, in particular the pages
"Customizing Indentation" and "Permanent Customization".

> Sona

Alan Mackenzie (Munich, Germany)
Email: address@hidden; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

reply via email to

[Prev in Thread] Current Thread [Next in Thread]