C++ Access Specifier Indentation


#1

I’ve been using Atom for a bit now as my primary editor, and it’s quite nice, but I’m having trouble finding options for configuring some of the auto-formatting related to C++. My coding style involves placing indentation before access specifiers, but Atom automatically unindents them on the first declaration, requiring that I go back and re-add the indent. Is there a way to configure the specifier indentation such that if I don’t indent ahead of time they will be indented or at least disabled so that it doesn’t remove my indentation?

An example:

class MyClass
{
	private:
		int _myInt;

	public:
		MyClass();
};

What Atom tries to enforce:

class MyClass
{
private:
	int _myInt;

public:
	MyClass();
};

Thanks in advance!


#2

Just a note, but MyClass(); should be indented once more in my example.


#3

What gets indented is determined by the language package’s settings. You can override this in your own config.cson. I know it doesn’t have the indent settings on the language-specific list in the Flight Manual, but trust me, it works. Just add this:

'.source.c, .source.cpp, .source.objc, .source.objcpp':
  'editor':
    'increaseIndentPattern': '(?x)
       ^ .* \\{ [^}"\']* $
      |^ .* \\( [^\\)"\']* $
      |^ \\s* (public|private|protected): \\s* $
      |^ \\s* @(public|private|protected) \\s* $
      |^ \\s* \\{ \\} $
      '
    'decreaseIndentPattern': '(?x)
       ^ \\s* (\\s* /[*] .* [*]/ \\s*)* \\}
      |^ \\s* (\\s* /[*] .* [*]/ \\s*)* \\)
      '

#4

Thanks! Wasn’t aware that Atom was using regex for things under the hood. A little disappointed that I have to manually edit config files to achieve what I’m looking for, but if it works…

Also, sorry for the delayed response, been busy recently so I didn’t really have time to sit down to read the response and respond.


#5

Look at it this way: there are so many potential language-specific settings that including all of them in the settings displays of languages would make those displays very long, and most of those settings aren’t things that the average user needs to change. I feel like the indentation rules are one of these things. I’d much rather have a newer user ask how to make a change to the behavior and give them the exact text to enter into the config file than to have people coming on here with Atom not indenting anything correctly because they made a change. Threads of the latter sort usually involve me asking extended questions to figure out exactly what’s going on, and are much less fun to help with.