# Override c++-mode font lock

I am improving the C++ highlighting in Emacs with the minor mode: modern-cpp-font-lock.

Consider this following C++14 code:

int main() { int i = 1'2'3l; }


From cppreference.com

Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.

In modern-cpp-font-lock, I set 1'2'3 to font-lock-constant-face and I set the integer suffix l to font-lock-keyword-face.

In fundamental-mode and modern-c++-font-lock-mode activated, I see the expected result. However, with c++-mode and modern-c++-font-lock-mode activated, '2' is highlighted as a string (l is correctly font locked).

I know the highlighting rely on the principle "first come first served" - meaning rules will not apply on words already highlighted.

Do you know if it is possible to override font-lock of a major mode? Or is it possible to change the order of rules to apply the font-lock (for example, longer rules first)?

Font-lock use two phases:

• The syntactic phase. In this phase, Emacs determines things like strings and comments.
• The keyword phase, i.e. the normal font-lock rules.

If you want to make Emacs ignore single quotes in digits, you have to do this in the first phase. Effectively, you will have to supply a custom syntax-propertize-function, which should set a suitable syntax-table text property on the quote character.