Highlight lexically bound variables
git clone https://git.jamzattack.xyz/lex-hl
Log | Files | Refs | LICENSE



This package provides a very primitive way to highlight lexically bound variables in Elisp code.


When reading (not writing) Elisp, I often find it hard to figure out which variables are bound where. I wanted a single keypress to highlight all the variables in a let form or lambda list.


An example, showing the highlighted source of lex-hl-prompt: lex-hl.png


The highlighting for each form (e.g. let, dolist, defun) is implemented as a separate function, added as a symbol property.

To add a new highlighter, simply define a function takes a single argument (a sexp, e.g. (let ((a 1) (b 2)) (+ a b))) and highlights the names of the variables bound within that sexp. Then, let lex-hl know about it with lex-hl-add-form.

The currently supported forms are:

  • cl-labels
  • dolist
  • let*
  • let
  • lambda
  • defun
  • defmacro



Download lex-hl.el, and use M-x package-install-file RET path/to/lex-hl.el.


Use the following recipe:

(lex-hl :type git
        :flavor melpa
        :repo "https://git.jamzattack.xyz/lex-hl")

Manual installation

  1. Download lex-hl.el
  2. Stick it in load-path
  3. Update autoloads
  4. (optionally) byte-compile it

Command index

  • Function: (lex-hl-unhighlight)

    Remove all hi-lock faces from the current buffer.

  • Function: (lex-hl-top-level)

    Highlight variables bound in the top level form at point. See the variable lex-hl-forms for a list of supported forms.

  • Function: (lex-hl-prompt bounds)

    Highlight variables bound in the form chosen from the minibuffer. This is limited to the region specified by BOUNDS which, interactively, is the top level form (aka defun) at point, or the active region with a prefix argument.

  • Function: (lex-hl-nearest n)

    Highlight variables bound in the Nth nearest form. See the variable lex-hl-forms for a list of supported forms.

  • Minor Mode: lex-hl-mode

    Add some keybindings to highlight lexical variables.

    • Keymap:
    C-c ' lex-hl-top-level
    C-c , lex-hl-prompt
    C-c . lex-hl-nearest
    C-c ` lex-hl-unhighlight