Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs indent template class/functions

Does anybody know how to inhibit emacs from indenting the name of functions or classes after a template clause?

Currenty the result is:

template <typename T>
    class A {
    /* ... */
    };

where I would like to have:

template <typename T>
class A {
/* ... */
};

Thank you very much for your help.

EDIT 1 I'm using c++-mode with java as indent style for c++. I customized the c-offset-alist in this way:

(custom-set-variables 
;;
'(c-offsets-alist (quote ((case-label . +) (innamespace . 0))))
like image 935
Luca Martini Avatar asked Nov 24 '10 09:11

Luca Martini


2 Answers

Go to the class line and hit TAB to perform the (unsolicited) indentation.
Then press Control-CControl-Oto display the indent mode fortopmost-intro-cont`

Press ENTER, then you can change the indent number (3 to 0 for instance).

At the end of your .emacs you can set permanently that instruction:

  (c-set-offset 'topmost-intro-cont 0 nil)
like image 71
Déjà vu Avatar answered Oct 10 '22 06:10

Déjà vu


There are different styles for indentation for Emacs' C++ mode. Quoting EmacsWiki:

A partial list of the better known C styles:

  • “gnu”: The default style for GNU projects
  • “k&r”: What Kernighan and Ritchie, the authors of C used in their book
  • “bsd”: What BSD developers use, aka “Allman style” after Eric Allman.
  • “stroustrup”: What Stroustrup, the author of C++ used in his book
  • “linux”: What the Linux developers use for kernel development
  • “python”: What Python developers use for extension modules
  • “java”: The default style for java-mode (see below)
  • “user”: When you want to define your own style

The c-default-style variable is what you need to change. Perhaps one of them will be what you need. Don't have Emacs right now, so I can't check them out.

like image 23
darioo Avatar answered Oct 10 '22 07:10

darioo