How can I get Emacs to indent my // comments with my code?
c, c++, emacs
Solution
You can inspect and change the value of the current indent by placing point on the concerned line and pressing `C-c C-o`. Adjust the relevant symbols to your liking.
This wont be permanent. Use direct invocation of the function `c-set-offset` in your `.emacs` to make the changes globally.
Simple example:
int main() {
//
}
This is my default indent. After moving the cursor to line 2 I see that the relevant symbol is `comment-intro`.
Using:
(c-set-offset 'comment-intro 6)
I get:
int main() {
//
}
Offset accumulates across symbols:
int main() {
//
{
//
}
}
Problem
I don't know much about Emacs, but after some googling, I edited my `.emacs` file to be as follows: ``` (setq c-default-style "bsd" c-basic-offset 4) ``` My goal was to get Allman-style indenting with 4-spaced tabs. It works as expected, but now my `//` comments aren't indented with my code. Before I changed this, when I would type `//`, it would get auto-indented to be in line with the rest of the code in the function. How can I get Emacs to auto-indent `//` comments? I've tried adding `c-indent-comments-syntactically-p 1` to the above `.emacs` file, but that didn't change it... For example: ``` int main() { // I'd like this line to be auto-indented to match the block for (int i = 0; i < 10; ++i) { // And this line to be auto-indented to match the block doStuff(); } } ``` Currently, `TAB` does not indent my `//` comment, and it doesn't automatically indent either.