I'm a long-term Emacs user who recently started to learn C++. I was surprised to discover that indentation for C++ is actually rather bad, specifically in files containing multi-line comment blocks.
In the example below I copy/paste a C++ exercise description into a multi-line comment block, then I start writing the main function. Notice that the main function header line is incorrectly indented. Notice that the closing bracket is incorrectly indented as well.
/* ch6_6
Write a program that checks if a sentence is correct according to the
“English” grammar in §6.4.1. Assume that every sentence is terminated
by a full stop (.) surrounded by whitespace. For example, `birds fly
but the fish swim .' is a sentence, but `birds fly but the fish swim'
(terminating dot missing) and `birds fly but the fish swim.' (no space
before dot) are not. For each sentence entered, the program should
simply respond “OK” or “not OK.” Hint: Don’t bother with tokens; just
read into a string using `>>'.
*/
int main() {
return 0;
}
If I remove the multi-line comment block indentation is correct, but multi-line comment blocks seem to be rather fundamental to writing real-world code.
This cannot possibly be right. Why does the present of a comment influence indentation at all? / What am I doing wrong here? I'm on GNU Emacs 25.2.1 (Fedora 25), started with emacs -q
.