6

With C++11, the keyword auto attained a new syntax and semantics. However, it seems that CC-mode has not been aware of this.

For example, if I write auto var = exp, I get var in green, in which various types are displayed. I don't like this; var should look like other variables.

How can I teach CC-mode to do this?

Pteromys
  • 185
  • 5

2 Answers2

6

One option is to add "auto" to extra types recognized by c++-mode:

(require 'cc-mode)
(add-to-list 'c++-font-lock-extra-types "auto")

The downside is that now it is not highlighted as a keyword any more. (But "auto" is both a type and a keyword, in a way.)

Constantine
  • 9,072
  • 1
  • 34
  • 49
2

Have a look at the package : "Modern C++" font-lock for Emacs. It is also available on Melpa.

Syntax highlighting support for "Modern C++" - until C++17 and Technical Specification. This package aims to provide a simple highlight of the C++ language without dependency.

It is recommended to use it in addition with the c++-mode major mode for extra highlighting (user defined types, functions, etc.) and indentation.

I am the maintainer of this minor mode. Any feedback is appreciated.