help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: replace TAB with 8 whitespaces


From: Alan Mackenzie
Subject: Re: replace TAB with 8 whitespaces
Date: Thu, 12 Jun 2003 17:26:53 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

jinneemop <jinneemop@isee.zju.edu> wrote on Fri, 13 Jun 2003 00:49:21 +0800:
> Hi all,
> I wish to use 8 spaces to indent source code under c++ mode. 
> When I press TAB, I'd like emacs to insert 8 spaces instead.
> How can I do this?

Finding the correct place in the Emacs info pages is the first challenge.
This can be done by:

C-h i
m emacs
m indentation

Then read through to the bit about "Just Spaces", which is exactly what
you're asking about.

Unfortunately, there are several ways to "solve" your problem, so here's
what's going on.

You need to set the variable indent-tabs-mode to nil.  This variable is
buffer-local, which means if you just set it, that setting only applies
to the current buffer.  If you are happy about always using spaces for
indentation (e.g. for other modes) you can change the default value of
this variable by putting this early on in your .emacs:

(setq-default indent-tabs-mode nil)

This is what I do.  If you just want this thing for c++ files, set the
variable in the c++-mode-hook, like this:

(defun my-nospaces ()
  (setq indent-tabs-mode nil))
(add-hook 'c++-mode-hook 'my-nospaces)

If you want a middle position, i.e. also using spaces in C Mode, Java
Mode, ... (all constituent modes of CC Mode), add the function to the
c-mode-common-hook instead of the c++-mode-hook, like this

(add-hook 'c-mode-common-hook 'my-nospaces)

All the best!

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; 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]