0

I want emacs to automatically reset it's indentation level to 0 at one specific point in a file.

For example: Because I have nested-nested-nested-.. namespaces, in the C++-Files I would like to not to indent the whole body inside the namespaces.

#include <vector>    
namespace qw {
namespace impl {

using std::vector;

class index_impl {
    vector<string> entries;
public:
    void add(const string &normalized, const string& original);
    string getBestMatch(const string& normalized) const;
};

} // namespace impl_multimap
} // namespace qw

This is only useful, of course, in these cases when there mainly one class to implement inside the nested namespaces. In header files this would be confusing. So I guess the best solution would be to have a special comment or something.

#include <vector>    
namespace qw {
namespace impl {
// -*- indent: 0 -*-

using std::vector;
...

Any other ideas would be ok, too.

1 Answer 1

0

Original Source.

Please put this line into your emacs file:

(c-set-offset 'substatement-open 0)

Detail method:

  1. Go to the line you want to indent

  2. Please type C-C C-O (not zero) and press Enter

  3. Now Type "0" and, press Enter for no extra indentation

  4. Please type Tab to reindent the line

  5. Future "{" will have the correct tab setting, until you restart emacs.

Additionally you can put this in your emacs file:

(c-set-offset 'SYNTACTIC-SYMBOL OFFSET)

to see the lisp code.

Learn to format C++ source outside of emacs here.

1
  • This will switch the indentation to 0, always, won't it? That's not what I need. I am more thinking of a manual tweaking in rare cases. astyle could help, yes, but I want to stay inside emacs.
    – towi
    Commented Aug 21, 2016 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .