Skip to content

Emacs Eglot support for clangd inactiveRegions LSP extension and ccls skippedRanges. Dim inactive ifdef code following build time options and defines.

License

Notifications You must be signed in to change notification settings

fargiolas/eglot-inactive-regions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eglot-inactive-regions

GNU ELPA

Emacs Eglot extension to visually style inactive preprocessor branches.

Highlights inactive code in a LSP aware way, taking into account compile time includes and defines for current project.

Features

  • Visual indication of inactive code: dimmed colors, shaded background or custom face can be used to quickly identify disabled code sections.
  • Automatic integration with eglot when the eglot-inactive-regions-mode global minor mode is enabled.

Shading styles

  • darken-foreground dims inactive code foreground colors
  • shade-background shades inactive code background (similar to eclipse style)
  • shadow-face applies the shadow face (or any face you like) to inactive code sections

Supported servers

  • clangd (since clangd-17) with inactiveRegions extension
  • ccls with skippedRanges extension. Still experimenting with this. Poorly documented, seems to emit notifications only on file save, feedback welcome!

Screenshots

darken-foreground style, gruvbox dark theme, 30% opacity

Inactive regions are provided by the language server so they will honor your include paths and compile time defines. Here I'm looking at my emacs-29 branch configured to build on MacOS and you can see Windows code is correctly disabled.

darken-foreground

shade-background style, modus operandi theme, 10% shading

shade-background

Requirements

  • emacs 29.1+
  • clangd with inactiveRegions support (clangd-17+)
  • ccls with skippedRanges support

Installation

It's in NonGNU ELPA so you can just install it with Emacs built-in package manager from M-x list-packages or just add it to your configuration with use-package as described below.

Usage

(use-package eglot-inactive-regions
  :custom
  (eglot-inactive-regions-style 'darken-foreground)
  (eglot-inactive-regions-opacity 0.4)
  :config
  (eglot-inactive-regions-mode 1))

Customization

M-x customize-group inactive-regions can be used to select the preferred shading style, customize text opacity and background shading or customize the base faces.

Caveats

As far as I know Emacs doesn't have a way to set foreground text opacity. Best would be a face attribute so that you can set it in an overlay covering each inactive region and be done with it. Unfortunately there is no attribute for this yet.

Hence darken-foreground style is a probably fragile and inefficient hack around fontification: for each inactive region it looks for symbols with different faces and applies to each of them a different overlay with a dimmed foreground color.

It seems to work with cc and c-ts modes and I've been using it daily for more than a year now, but could totally break other modes or features I'm not aware of.

If you know a better way please do let me know.

About

Emacs Eglot support for clangd inactiveRegions LSP extension and ccls skippedRanges. Dim inactive ifdef code following build time options and defines.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published