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?

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.)

  • I actually wanted auto to be highlighted as a type, so it is not a downside :) – Pteromys Nov 27 '14 at 20:58
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.