jscheid / dtrt-indent

A minor mode that guesses the indentation offset originally used for creating source code files and transparently adjusts the corresponding settings in Emacs, making it more convenient to edit foreign files.
187 stars 31 forks source link

Add cmake-mode support. #56

Closed azuk closed 3 years ago

azuk commented 3 years ago

I don't actively use CMake so the "syntax table" entries might not make sense nor be complete. I'm not sure why single line comments are excluded in case of, say, C++ (I'd expect them to be indented just like normal code lines). But they are, so I did that as well to be consistent.

rrthomas commented 3 years ago

Thanks for this! What makes you think single-line comments are excluded in C++?

azuk commented 3 years ago

Thanks for this! What makes you think single-line comments are excluded in C++?

I didn't read the code but based on the doc string of dtrt-indent--for-each-indentation I got the impression that the purpose of "syntax table" entries is to skip lines when going through indentations (the doc string of dtrt-indent-language-syntax-table itself describes the structure of the syntax table and its entries but not the purpose/use of them). And for c/c++/java "language" there is an entry with begin regexp "//" and end regexp "$".

rrthomas commented 3 years ago

Ah yes, what you say makes sense. But maybe it's still sensible to exclude single-line comments from analysis.

What about bracket comments for cmake?

azuk commented 3 years ago

Now that I looked at the code and experimented with it, I see that I was mistaken about the behaviour. Indentation of lines with single line comments (even if there is nothing else but the comment) is considered, the lines are not skipped. However, the comments need to be skipped because otherwise another syntax table entry might match inside them and, for example in case of an unmatched double quote, end up skipping several subsequent lines.

I added support for bracket comments, a new feature since the last time I used CMake.

rrthomas commented 3 years ago

Many thanks!