Emacs Lisp Mode Syntax Coloring Problem

By Xah Lee. Date: . Last updated: .

This page gives discuss a problem of emacs's “emacs-lisp-mode”'s syntax coloring.

Emacs has a mode for editing emacs lisp code. The mode is called emacs-lisp-mode. However, the syntax highlighting in emacs-lisp-mode only color very few emacs lisp keywords.

For example:

Here's a example of elisp source code colored by emacs-lisp-mode:

screenshot emacs lisp mode 2017 01 03
emacs-lisp-mode

Here's a desired coloring:

screenshot xah elisp mode 2017 01 03
xah-elisp-mode

In many language modes, all the language's keywords are syntax colored. They are colored differently according to the keyword's role (For example, {function, class, object, type, operator, …}). If you don't like so many colors, you can set font-lock-maximum-decoration to 1, 2, or 3, for progressively more colors. However, in emacs-lisp-mode, only a subset of keywords are colored, and emacs-lisp-mode doesn't support customize-group, nor levels for font-lock-maximum-decoration. So, you are stuck with the most basic coloring of a subset of keywords.

It is suggested that the mode only color a special class of elisp symbols called “special forms” (see: (info "(elisp) What Is a Function")). However, that is not true. or is a special form, but is not colored.

I think the symbols chosen to color is heuristic based for the goal of ease-of-reading. Namely, keywords that are likely to be significant and starting a code block are colored. (example: {let, lambda, if, unless, while, progn, cond, condition-case, save-excursion, with-current-buffer, with-selected-window, with-output-to-temp-buffer, with-selected-window}, and few more.) However, the coloring scheme is unpredictable, inconsistent, and difficult to understand.

If emacs-lisp-mode colors all built-in symbols by their semantics class (For example, function, command, variable, macro, special form …), with support for levels of font-lock, the advantage of highlighting only significant keyword can be maintained, while making it more systematic, understandable, and flexible.

This report applies to at least GNU Emacs 22.2 to GNU Emacs 24.3.1

This essay is originally posted to gnu.emacs.help newsgroup. I filed this as emacs bug report, debbugs.gnu.org #2630.

Fix: Emacs: Xah Emacs Lisp Mode

I started to build a mode to fix this. See: Emacs: Xah Emacs Lisp Mode.

Emacs Modernization

  1. Simple Changes Emacs Should Adopt
  2. Why Emacs Keys are Painful
  3. Problems of the Scratch Buffer
  4. M-key Notation vs Alt+key Notation
  5. Menu Problem
  6. Mode Line Problem
  7. cua-mode Problems
  8. kill-buffer Induces Buffer Accumulation
  9. Emacs Form Feed ^L
  10. Inconsistency of Search Features
  11. Single Key to Delete Whole Line
  12. Emacs HTML Mode Sucks
  13. Emacs Does Not Support Viewing Images Files In Windows
  14. Emacs Spell Checker Problems
  15. Adopt HTML as Texinfo Replacement
  16. Support HTML Mail
  17. Problems of “man” Command
  18. Emacs Lisp Mode Syntax Coloring Problem
  19. Emacs Ahk Mode Problems
  20. Problems of Emacs's Manual
  21. Problems of Emacs's Manual; Examples
  22. Emacs: Have You Read Emacs Manual?
  23. Elisp: Ban Syntax Table
  24. Emacs: Make elisp-index-search use Current Symbol
  25. Emacs: Usability Problems of Mode Documentation
  26. Emacs GNU Texinfo Problems; Invalid HTML
  27. A Record of Frustration in IT Industry; Disappearing FSF URLs, 2006
  28. Emacs Manual Node Persistency Issues
  29. Emacs: dired-do-query-replace-regex Replace ALL (fixed)
  30. Problems of Emacs Supporting Obsolete Systems
  31. Elisp: Function to Copy/Delete a Dir Recursively (fixed)
  32. Thoughts on Common Lisp Scheme Lisp Based Emacs
  33. Text Editors Popularity and Market Research
  34. Text Editor's Cursor Movement Behavior (emacs, vi, Notepad++)
  35. GNU Emacs Development Inefficiency
  36. Emacs Dev Inefficiency and Emacs Web 2.0?
  37. Letter-Case Commands Usability Problems
  38. Emacs: Select Line, between Quotes, Extend Selection
  39. Emacs: isearch Current Word
  40. Suggestions on Line Wrap Commands
  41. Emacs: Single Key to Delete Whole Line
  42. Emacs Undo and Emacs Cult Problem

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc