4

Question

Pretty straightforward: How to highlight constexpr in cc-mode (editing C++ code)?

Example

If I use const as in the following example

const double = 3.14

const gets highlighted as a keyword(1) (i.e., in pink), while if I write

constexpr double = 3.14

constexpr gets highlighted as all-faces (i.e., no highlighting at all).

Ideally, a simple solution like writing

(add-to-keywords "constexpr") ;; pseudo-code

in my .emacs without tinkering with the code of cc-mode would be the best for me.

Addendum

This question might be related: Change the way CC-mode font-lock the C++11 auto syntax.

Note

(1) I think that it is a keyword because placing the pointer on the word and doing M-x customize-face RET I get: Customize face (default ``font-lock-keyword-face'): and pressing RET I get redirected to the “Easy Customization” wizard.

Pier Paolo
  • 275
  • 3
  • 10

1 Answers1

3

The incantation you want is:

(font-lock-add-keywords 'c++-mode
                        '(("constexpr" . 'font-lock-keyword-face)))
erikstokes
  • 12,686
  • 2
  • 34
  • 56
  • 1
    It's [dotted pair](https://www.gnu.org/software/emacs/manual/html_node/elisp/Dotted-Pair-Notation.html#Dotted-Pair-Notation) syntax for a cons cell. If you leave out the "." the keywords get interpreted differently. See the help for `font-lock-keywords` for what a "non-dotted" list would mean. – erikstokes Mar 02 '15 at 23:07