C++ font-lock for Emacs


License GPL 3 MELPA Build Status

Donate Paypal

Syntax highlighting support for "Modern C++" - until C++20 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.


With modern-c++-font-lock-mode:

Using GNU Emacs 27.0.50 and CC Mode version 5.33.2.



modern-cpp-font-lock is available on the major package.el community maintained repo - MELPA.

You can install it with the following command:

M-x package-install [RET] modern-cpp-font-lock [RET]

In your init Emacs file add:

(add-hook 'c++-mode-hook #'modern-c++-font-lock-mode)


(modern-c++-font-lock-global-mode t)


In your init Emacs file add:

(use-package modern-cpp-font-lock
  :ensure t)


Global setup

Download modern-cpp-font-lock.el into a directory of your load-path. Place the following lines in a suitable init file:

(require 'modern-cpp-font-lock)
(modern-c++-font-lock-global-mode t)

modern-c++-font-lock-mode will be activated for buffers using the c++-mode major-mode.


For the current buffer, the minor-mode can be turned on/off via the command:

M-x modern-c++-font-lock-mode [RET]


C++ Language

You can modify the following lists to recognize more words or set it to nil to partially disable font locking:

  • modern-c++-attributes - [[deprecated]], [[noreturn]], etc.
  • modern-c++-keywords - if, constexpr, noexcept, etc.
  • modern-c++-operators - ...
  • modern-c++-preprocessors - #define, __LINE__, __cplusplus, etc.
  • modern-c++-types - bool, char, double, etc.

Set to t (default value) to enable the following options or otherwise to nil:

  • modern-c++-literal-boolean - false, true
  • modern-c++-literal-integer - 0b101010, 18446744073709550592LLU, 0XdeadBABEu, etc.
  • modern-c++-literal-null-pointer - nullptr
  • modern-c++-literal-string - R"xyz()")xyz", L"hello\ngoodbye", "abcd", etc.

Configure the following list to customize font locking for literal integers:

  • modern-c++-literal-binary-prefix-face
  • modern-c++-literal-binary-infix-face
  • modern-c++-literal-binary-suffix-face
  • modern-c++-literal-octal-prefix-face
  • modern-c++-literal-octal-infix-face
  • modern-c++-literal-octal-suffix-face
  • modern-c++-literal-hex-prefix-face
  • modern-c++-literal-hex-infix-face
  • modern-c++-literal-hex-suffix-face
  • modern-c++-literal-dec-infix-face
  • modern-c++-literal-dec-suffix-face

C++ standard library

Set to t (default value) to enable the following font lock options. Otherwise use nil:

  • modern-c++-stl-cstdint - Define the header <cstdint>

Mode line

When modern-c++-font-lock-mode is activated, mc++fl is displayed.


The Wiki is available: https://github.com/ludwigpacifici/modern-cpp-font-lock/wiki


Font-lock keywords are tested with the faceup package of Anders Lindgren.


If you find a bug, please check if you can reproduce with c++-mode only. If it is the case, send your bug upstream to CC Mode

Do not hesitate to ask questions or share suggestions.

Happy coding!


  • Templates


    Highlighting template parameters have been one thing that have never worked consistently for me in emacs. I tried installing modern-cpp-font-lock, but I'm still getting the following hightlighting:


    The template paramters Features and Model are not hightlighted, but above State is.

    Any ideas for how to fix this?

    opened by nickjmeyer 13
  • Add support for raw string literals?

    Add support for raw string literals?

    The regexs here seem to work once you apply the correction from the comments, so something like:

           ("\\(\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(\\)" 1 font-lock-keyword-face t) ; start delimiter
           (   "\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(\\([[:ascii:][:nonascii:]]*?\\))[^\\s-\\\\()]\\{0,16\\}\"" 1 font-lock-string-face t)  ; actual string
           (   "\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}([[:ascii:][:nonascii:]]*?\\()[^\\s-\\\\()]\\{0,16\\}\"\\)" 1 font-lock-keyword-face t) ; end delimiter
    opened by davidshepherd7 6
  • Highlighting numeric literals

    Highlighting numeric literals

    First off, I should say, this has been a really helpful package. Really nice to have the improved highlighting. Makes editing that much easier!

    When there are numerical characters in a function name or variable name, if they follow an underscore, start with zero, and have at least one additional digit then they are highlighted as a literal.


    You can see that it doesn't happen without the underscore. Also, if it is just a zero or if there is no zero then it is also okay.

    opened by nickjmeyer 5
  • Inclusion in Emacs core

    Inclusion in Emacs core

    I am opening this issue after seeing the reddit post below. https://www.reddit.com/r/emacs/comments/94j39z/modern_c_font_lock_in_emacs/

    Could you make the effort and email the emacs mailing list for your plugin to be included in the Emacs core?

    opened by innerout 4
  • second function argument type is rendered as a variable

    second function argument type is rendered as a variable

    The function declarations below highlight ABC as a function variable instead of a type void foo(std::string&, ABC); void foo(string s, ABC abc) However void foo(string&, ABC); and void foo(std::string, ABC); correctly hightlight ABC as a type.

    My modern-cpp-font-lock version is 0.1.3 installed from Melpa, emacs version is 24.5.1 the system is emacs Would you please investigate this problem? Thank you!

    opened by TooChaos 4
  • "const override" is not correctly highlighted

    Thank you for this package.

    Using c++-mode and modern-c++-font-lock-mode the following code

    struct b : public a
      void foo() override;
      void foo() const override;

    is font-locked as


    as if the second override was not detected as a keyword.

    Would that be easy to fix?

    opened by adl 4
  • Hexadecimal digits prefix highlights as keyword

    Hexadecimal digits prefix highlights as keyword


    It can be reproduced using the following init.el with emacs -Q -l init.el.

    (require 'package)
    (setq package-archives
          '(("gnu"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
            ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
    ;; Bootstrap `use-package'
    (unless (package-installed-p 'use-package)
      (package-install 'use-package))
      (require 'use-package))
    (use-package modern-cpp-font-lock
      :ensure t
      :hook (c++-mode . modern-c++-font-lock-mode))
    (provide 'init)

    emacs --version

    GNU Emacs 28.0.50
    Copyright (C) 2020 Free Software Foundation, Inc.
    GNU Emacs comes with ABSOLUTELY NO WARRANTY.
    You may redistribute copies of GNU Emacs
    under the terms of the GNU General Public License.
    For more information about these matters, see the file named COPYING.

    cc-mode version

    ;; Version: 5.33.1

    After reading the source, it seems like a feature but a bug.


    opened by condy0919 3
  • clash between modern-c++-font-lock-mode and built-in c++-mode

    clash between modern-c++-font-lock-mode and built-in c++-mode

    Example code: void f() { aut s = R"EOF("a)EOF"; } If I set fundamental-mode and enable modern-c++-font-lock-mode then the raw string is highlighted perfectly so the modern fontifying is working. However if I set c++-mode then modern-c++-font-lock-mode then it is highlighted the old C++ way - it looks like the built-in c++ fontification is over-riding the modern rules.

    To reduce uncertainty I ran this with emacs --no-init so no other ealpa packages are loaded: (load-library "~/.emacs.d/elpa/modern-cpp-font-lock-0.1.3/modern-cpp-font-lock.el") Using CC Mode version 5.32.99 GNU Emacs 25.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.26) of 2018-01-12

    I can try to debug this but I'd like some hints where to look. I'm familar with elisp programming but not the font-lock stuff specifically.

    opened by alanconway 3
  • Integer literal font lock

    Integer literal font lock

    I'm having some issues with the interger literal when using the single quote. I grabbed the examples from your test file.

    Here is what I get with modern cpp mode enabled.

    screenshot from 2018-03-10 13-22-12

    Here is what I get with modern cpp mode disabled.

    screenshot from 2018-03-10 13-25-23

    opened by nickjmeyer 3
  • String literals isn't showing correctly when there are quotes

    String literals isn't showing correctly when there are quotes

        std::string empty = R"EOF({                                                                                                                                                                                                                                                   
        "test1": {},                                                                                                                                                                                                                                                                  
        "test2": [],                                                                                                                                                                                                                                                                  
        "test3": [],                                                                                                                                                                                                                                                                  
        "test4": []                                                                                                                                                                                                                                                                   

    The line above did not appear correctly. Installed version: 20180110.1231

    opened by yerbie 3
  • Raw strings do not work

    Raw strings do not work

    The documentation suggests that raw strings should be properly highlighted, but this does not seem to work. To reproduce this, I started from a completely clean .emacs file and then ran:

    (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
    (package-install 'modern-cpp-font-lock)
    (modern-c++-font-lock-global-mode t)

    I then opened a new C++ file, verified that modern-c++-string-literal was indeed t, but unfortunately still do not get proper highlighting:


    opened by stanford-scs 3
  • Variable

    Variable "Is_PragmaLexer" isn't correctly highlighted


    It can be reproduced using the following code:

    struct foo {
      bool isPragmaLexer() const {
        return Is_PragmaLexer;
      bool Is_PragmaLexer;
    opened by condy0919 0
  • operator

    operator""() wrecks font-lock

         constexpr auto operator""m(unsigned long long l) { return quantity<metre, std::int64_t>(l); }                                                                                                                                                                                                                                                                  

    which is trying to define a UDL in this library


    opened by oschonrock 2
  • Trouble with attributes

    Trouble with attributes

    When I give a function an attribute, the function name is no longer fontified. When I write a function: int myfunction() { /*...*/ } it is fontified correctly. But if I add any attribute: [[nodiscard]] int myfunction() { /*...*/ } the function name myfunction is now just the default text color. This happens with multiple

    opened by red-patriot 1
  • trouble with string literals

    trouble with string literals

    I'm using stock Ubuntu 18.04. I creates a simple setup without any of my init, and I cannot get the color of this small c++ program to work correctly.

    #include <string>
    std::string a = R"raw(Hi there I'm a Qoute " guy)raw";
    int main(){}

    Everything after the end double quote on line 2 is colored as if it were inside a string. It does not seem to recognize the double quote before guy as being inside the string.

    I'm running emacs like this:

    emacs -q --load testinit.el

    the contents of my init file (testinit.el) are:

    (add-to-list 'load-path "/home/mat/tmp/cppfl/modern-cpp-font-lock")
    (require 'modern-cpp-font-lock)
    (modern-c++-font-lock-global-mode t)

    I've cloned a copy or your repo here, at revision 02f104701b. The test directory, /home/mat/tmp/cppfl, looks like:


    I'm on emacs 25.2.2.

    opened by kookjr 2
Je pompe, donc je suis.
C/C++ language server supporting multi-million line code base, powered by libclang. Emacs, Vim, VSCode, and others with language server protocol support. Cross references, completion, diagnostics, semantic highlighting and more

Archived cquery is no longer under development. clangd and ccls are both good replacements. cquery cquery is a highly-scalable, low-latency language s

Jacob Dufault 2.3k Jan 2, 2023
A C/C++ minor mode for Emacs powered by libclang

Irony-Mode A C/C++ minor mode powered by libclang irony-mode is an Emacs minor-mode that aims at improving the editing experience for the C, C++ and O

Guillaume Papin 897 Dec 22, 2022
MINCE is an Emacs-like text editor from Mark of the Unicorn, Inc.

MINCE Is Not Complete[ly] EMACS Overview MINCE is an Emacs-like text editor from Mark of the Unicorn, Inc. Versions were available for many oper

Jeffrey H. Johnson 20 Nov 5, 2022
tree-sitter grammar for emacs lisp

Tree-sitter Grammar for Emacs Lisp A simple tree-sitter grammar for elisp. Syntax supported: Atoms (integers, floats, strings, characters, symbols) Li

Wilfred Hughes 30 Dec 7, 2022
te is a small text editor with emacs keybindings.

te - a tiny emacs te is a small text editor with emacs keybindings. Here are söme Ümlautß! Oh no. Come, you spirits That tend on mortal thoughts, unse

Leah Neukirchen 21 Nov 5, 2022
Support for TrueType (.ttf) font files with Simple Directmedia Layer.

This library is a wrapper around the excellent FreeType 2.0 library

Simple Directmedia Layer 192 Dec 31, 2022
A font cooking library

Font Chef Font Chef is a cross-platform C99 and C++ library to create character atlas of pre-rasterized glyphs from a font at a specified size and col

Leonardo Guilherme de Freitas 45 Apr 25, 2022
font rendering, Zep vim emulator, microui integration

LabFont This project is an exploration of getting text into a rendeing pipeline based on @floooh's sokol. Frameworks such as Dear ImGui solve text ren

Nick Porcino 14 Sep 11, 2022
Portable, Noto-powered font-rendering abstraction based on FreeType and Raqm

Mechascribe Mechascribe is still under construction and nothing is functional yet. Mechascribe is a text rendering abstraction trying to support as mu

null 4 Jan 27, 2022
A terminal-based, mouse-driven BDF (bitmap) font editor.

bdfedit A terminal-based, mouse-driven BDF font editor. Capable of reading, writing, and editing bitmap font files fully within the terminal, and enti

Andrew 7 Dec 24, 2022
Free (libre) font editor for Windows, Mac OS X and GNU+Linux

FontForge FontForge is a free (libre) font editor for Windows, Mac OS X and GNU+Linux. Use it to create, edit and convert fonts in OpenType, TrueType,

null 5k Dec 27, 2022
cross-platform bitmap font implementation

Component for rendering text with bitmap font on all openfl targets. This set of classes is heavily based on classes from pixelizer (https://github.co

Zaphod 49 Oct 26, 2021
A Fingerprint Door Lock using a microprocessor named Arduino UNO and programming through Arduino IDE

INSTRUCTIONS - The codes for the Fingerprint Door lock are present in the Code For Fingerprint Door Lock folder The instructions of how to operate the

Akhil Sahukaru 15 Mar 3, 2022
Lock you keyboard and clean your screen. A simple, and easy way to clean your computers.

Pristine Cleaner A screen and keyboard cleaning application made to turn screen black, and lock keyboard for easy cleaning. With features such as star

Rhino Inani 2 Jan 16, 2022
Smart door lock system using Arduino

Smart door lock system using Arduino จำลองระบบรักษาความปลอดภัยของบ้าน โดยการใส่รหัสผ่าน Keypad เมื่อใส่รหัสถูกจะผ่านประตูเข้ามาได้ ซึ่งใส่รหัสผิดได้ไม

null 1 Nov 6, 2021
Fingerprint doorlock Arduino project make from Fingerprint sensor and Solenoid door lock

Fingerprint-doorlock Fingerprint doorlock Arduino project make from Fingerprint sensor and Solenoid door lock Main Idea Create Doorlock that uses Fing

Narongkorn 1 Dec 15, 2021
TTGO GPS lock fix with platformio

TTGO_T-beam_GPS-reset converted for easy upload with platformio Based on Fork by ErikThevking https://github.com/eriktheV-king/TTGO_T-beam_GPS-reset T

null 2 May 11, 2022
Monitor based on perf_event: split-lock, irq-off, profile, task-state, watchdog, kmemleak, kvm-exit, mpdelay

基于perf的监控框架 基于libperf和libtraceevent库实现简单的监控框架,提供比perf更灵活的特性。 数据不落盘。 数据过滤,基于tracepoint的过滤机制,减少数据量。 数据实时处理并输出。不需要存盘后再处理。 基于perf_event_open系统调用。 虽然比perf更

null 23 Dec 20, 2022
A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store

SimDB A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store. SimDB is part of LAVA (Live A

null 454 Dec 29, 2022