Syntax highlighting

clojure-mode provides basic syntax highlighting for Clojure(Script) code, but CIDER builds upon this in several ways. The biggest limitation of clojure-mode is that the syntax highlighting there is based on the usage of regular expressions to figure out what’s the syntactic category of the various identifiers (e.g. constants, macros, types, etc). CIDER, however, has access to all the data about identifiers from code that has already been loaded into nREPL, so it can provide a richer and more accurate syntax highlighting. We call this functionality "dynamic syntax highlighting" (as opposed to the somewhat static syntax highlighting you’d get from clojure-mode).

Dynamic syntax highlighting

The Emacs term for "syntax highlighting" is "font-locking". That’s why all configuration variables that have something to do with syntax highlighting have "font-locking" in their names.

CIDER can syntax highlight symbols that are known to be defined. By default, this is done from symbols from the clojure.core and cljs.core namespaces, as well as macros from any namespace. If you’d like CIDER to also colorize usages of functions and variables from any namespace, do:

(setq cider-font-lock-dynamically '(macro core function var))

Here’s how code looks without dynamic syntax highlighting.

Dynamic Font-lock Off

And here’s how the code looks when it’s turned on.

Dynamic Font-lock On

You can refer to the cider-font-lock-dynamically Elisp documentation for further details.

Syntax highlighting for reader conditionals

By default CIDER will apply font-locking to unused reader conditional expressions depending on the buffer’s CIDER connection type.

Reader Conditionals

You can disable this behavior by adjusting cider-font-lock-reader-conditionals:

(setq cider-font-lock-reader-conditionals nil)

Customizing CIDER faces

CIDER defines a few custom faces that you might want to adjust (although normally your color theme should take care of them):

  • cider-deprecated-face - used for syntax highlighting deprecated vars

  • cider-instrumented-face - used for syntax highlighting instrumented for debugging vars

  • cider-traced-face - used for syntax highlighting traced vars

  • cider-reader-conditional-face - used for syntax highlighting inactive reader conditional branches