Based on some playing around, it would appear that it’s pulling the indent level from the indentation of the last text of the comment text as you have noticed. which definitely seems wrong to me.
Workarounds to defeat this include using C++ style comments instead:
// This is a long comment
// which continues on next line
#define TEST 123
|
or adding an extra line at the end of your comments that makes the indent jump to the first column in this case:
/* This is a long comment
which continues on next line
.
*/
#define TEST 123
|
However, I am fiercely against tools dictating what my commenting style should look like, so I dug a little deeper.
According to this doc page and the current contents of the indentation rules for C++ (and sister languages like C), a modification to the decreastIndentPattern
can be made to tweak this behavior.
What I did was use PackageResourceViewer to open the C++ Indentation Rules.tmPreferences
file, and modify the decreaseIndentPattern
key as follows, then save the file.
<key>decreaseIndentPattern</key>
<string>(?x)
^ (.*\*/)? \s* \} .* $
| ^ \s* (public|private|protected): \s* $
| ^ \s* @(public|private|protected) \s* $
| ^ \s* #
</string>
That last line is what I added, which matches any line that starts with a #
character and decreases the indent level, which is (to me) the desired behavior in this particular case.
This creates a file in your Packages/C++
directory that overrides the default settings, so note that if you do this and the default package changes something in this file, you’ll still be overriding it and thus not see those changes.
Note however that I am by no means an expert in how the sublime indenting system works and I didn’t do any super extensive testing, so while this works for fixing this particular issue, I don’t know if it might cause other issues or inconsistencies. For example, if you’re editing code with conditional defines in it, this will (probably) break any auto-indenting in the surrounding code, which is probably something you want to have happen.