An Emacs package that integrates with C++ Insights, a tool that transforms C++ source code into its expanded form, revealing the details the compiler sees after applying language features like templates, operator overloading, and lambda functions.
This package allows you to run C++ Insights directly from within Emacs, displaying the transformed code in a separate buffer. It helps C++ developers understand how the compiler interprets their code, making it easier to debug complex C++ features and learn about the language's inner workings.
Before using this package, you need to install the C++ Insights command-line tool:
- Install WSL (Windows Subsystem for Linux)
- Follow the Ubuntu instructions below within WSL
Using Homebrew:
brew install cmake llvm
git clone https://github.com/andreasfertig/cppinsights.git
cd cppinsights
mkdir build && cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_COMPILER=clang++ ..
make
sudo make installsudo apt-get install cmake clang libclang-dev llvm
git clone https://github.com/andreasfertig/cppinsights.git
cd cppinsights
mkdir build && cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
make
sudo make installUsing AUR:
pamac install cppinsights(use-package cppinsights
:straight (:host github :repo "chrischen3121/cppinsights.el")
:commands cppinsights-run
:custom
;; Customize variables as needed
(cppinsights-binary "insights") ;; Path to the insights binary
(cppinsights-extra-args '("-std=c++17")) ;; Additional arguments to pass to C++ Insights
:bind
;; Add keybinding for cppinsights-run
(:map c++-mode-map
("C-c c i" . cppinsights-run)))
In packages.el:
(package! cppinsights
:recipe (:host github :repo "chrischen3121/cppinsights.el"))In config.el:
(use-package! cppinsights
:commands cppinsights-run
:custom
(cppinsights-program "insights") ;; Path to the insights binary
(cppinsights-clang-opts '("-O0" "-std=c++17")) ;; Additional arguments to pass to internal clang
:init
;; Add keybinding for cppinsights-run
(map! :map c++-mode-map
:desc "Run C++ Insights" "C-c i" #'cppinsights-run))(package-vc-install '(cppinsights :url "https://github.com/chrischen3121/cppinsights.el"))- Open a C++ file in Emacs
- Run
M-x cppinsights-runto process the current file - A new buffer will open showing the transformed code
You can customize the package by:
M-x customize-group RET cppinsights RET
You can add a key binding to your Emacs configuration:
(keymap-set c++-mode-map "C-c c i" #'cppinsights-run)