我一直在研究现有的 C++ 代码风格工具,但还没有找到任何软件包可以让我突出显示文件中破坏详细代码风格配置的部分。虽然基本代码样式设置似乎有几个选项(应该/不应该缩进的内容、行长度 > 某个阈值等),但其他问题似乎没有得到解决。对于上下文,我希望能够识别我何时执行以下操作:
- { 与函数定义在同一行(应该是下一行)
- { 在 if 语句之后的下一行(应该在同一行)
- ) 和 { 之间没有空格
- 比较之间没有空格(应该是 a == b 而不是 a== b、a==b 等)
- 连续换行
- 键入 *var_name 或键入 * var_name 而不是 type* var_name
- 等等...
这种风格在我的团队中被严格执行,我很难将不一致的情况降到最低。我正在寻找允许我广泛自定义这些设置的现有 emacs 工具,或者寻找有关如何自己创建 emacs 包的建议来识别这些错误。
最佳答案
正如 Noufal 所建议的,Flymake 是一种选择。
另一个是Flycheck .几年前我从 Flymake 转到了 Flycheck,之后就再也没有回头。 Flycheck 支持大量语言和工具,并且似乎比 Flymake 需要更少的手工操作。
来自其GitHub README :
Features
- Supports over 30 programming and markup languages with more than 60 different syntax checking tools
- Fully automatic, fail-safe, on-the-fly syntax checking in background
- Nice error indication and highlighting
- Optional error list popup
- Many customization options
- A comprehensive manual
- A simple interface to define new syntax checkers
- A “doesn't get in your way” guarantee
- Many 3rd party extensions
对于 C 和 C++ 代码,Flycheck 支持 Clang and Cppcheck out of the box , 并且有一个 plugin for Google's C++ style guide
当然你可以add your own checkers如果你愿意的话。
关于c++ - 如何配置 Emacs 以突出显示违反详细代码样式的 C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23962296/