I've just joined a company which uses tabs to indent C++ code. It seems
that all of the auto indentation in cc-mode is space based. My
questions are: Am I the only one in the world with this problem? Am I
just missing something obvious to make cc-mode indent with tabs instead
of spaces? If cc-mode can't do it, has an auto-indent mode been written
for emacs?
I've done search of the web and I can't find anything close to what I'm
looking for. If this is the wrong list for this type of question please
address me to a better one.
Malik
Kai Großjohann wrote:
>
> Malik Coates <malik...@flashmail.com> writes:
>
> > I've just joined a company which uses tabs to indent C++ code. It seems
> > that all of the auto indentation in cc-mode is space based. My
> > questions are: Am I the only one in the world with this problem? Am I
> > just missing something obvious to make cc-mode indent with tabs instead
> > of spaces? If cc-mode can't do it, has an auto-indent mode been written
> > for emacs?
>
> Syntax driven indentation normally computes the number of columns to
> indent. Whether tabs or spaces are used to indent that many columns
> is something different entirely.
>
> Suppose that the syntax driven indentation has computed a nine-column
> indentation for a specific line.
>
> If you put (setq-default indent-tabs-mode nil) into your ~/.emacs file
> (this might be the default value), Emacs will use nine spaces and no
> tabs.
>
> With (setq-default indent-tabs-mode t) and the default tab-width
> setting of 8, Emacs will use one tab and one space for the nine
> columns (to minimize the number of characters).
>
> You can change the tab-width variable, too. For example, with
> tab-width set to 5, Emacs would use one tab and four spaces for the
> nine columns.
>
> How does Emacs compute the number of columns for indentation? That's
> done by CC mode and you can configure it as described in the CC mode
> info file. Often, c-basic-offset determines the number of columns to
> indent, for example:
>
> if (foo) {
> bar;
> }
>
> In the above fragment, the middle line was indented four columns, the
> c-basic-offset setting for this hypothetical example.
>
> This way, if you set tab-width to be the same as c-basic-offset,
> you'll get one tab per indentation step.
>
> But sometimes, CC mode uses indentation which is not a multiple of
> c-basic-offset, for example in the following:
>
> function_name(some_long_argument_goes_here,
> second_arg_also_quite_long);
>
> Here, the indentation of the second line depends on the length of the
> function name. I'm sure you can see where the necessity for spaces
> creeps in.
>
> Some brain-dead editors use an indentation like the following:
>
> function_name(some_long_argument_goes_here,
> second_arg_also_quite_long);
>
> Here, the second line is always indented four columns, one indentation
> step. I find this rather hard to read. But the CC mode info file
> explains you how to customize it to give you this brain-dead
> indentation, if you so desire. (In a nutshell: type &pi0;C-c C-o' on the
> line where you want to correct indentation, follow the prompts. Hit
> TAB to check indentation. When indentation is okay, you can add the
> c-set-offset statement to your ~/.emacs file as explained in the CC
> mode info file.)
>
> kai
> --
> I like BOTH kinds of music.
>
>
Malik> I've just joined a company which uses tabs to indent C++
Malik> code. It seems that all of the auto indentation in
Malik> cc-mode is space based. My questions are: Am I the only
Malik> one in the world with this problem? Am I just missing
Malik> something obvious to make cc-mode indent with tabs instead
Malik> of spaces? If cc-mode can't do it, has an auto-indent mode
Malik> been written for emacs?
I believe the default behavior is to use a mixture of tabs and spaces
for indentation.
What is the value of the variable 'indent-tabs-mode'? You probably
want it to be 't'.
Do you mean you _only_ want to use tabs for indentation, and no spaces
at all? (ick) In that case, the only thing I can think of to do is:
(defun my-c++-mode-setup ()
(local-set-key [TAB] 'tab-to-tab-stop))
(add-hook 'c++-mode-hook 'my-c++-mode-setup)
And thus basically ignore cc-mode's indentation capabilities. I hope
someone else has a better solution, but perhaps setting
'indent-tabs-mode' to 't' will do what you want.
if (foo) {
bar;
}
function_name(some_long_argument_goes_here,
second_arg_also_quite_long);
function_name(some_long_argument_goes_here,
second_arg_also_quite_long);
indentation, if you so desire. (In a nutshell: type `C-c C-o' on the