$ show clojure-emacs/clojure-mode
This repository contains `clojure-mode`, an Emacs major mode for editing Clojure, ClojureScript, and related languages. The system provides syntax highlighting (font-lock), indentation, navigation, and a suite of refactoring commands directly in the editor. The architecture is a single large Emacs Lisp file (`clojure-mode.el`) with an additional extra font-locking package. It defines a base `clojure-mode` derived from `prog-mode`, plus derived modes for ClojureScript, ClojureC, ClojureDart, Joker, Jank, and EDN data files. Key entry points are the mode activation functions and interactive commands like `clojure-align`, `clojure-thread`, `clojure-cycle-privacy`, etc. The indentation engine uses a backtracking algorithm that walks up the sexp tree to apply contextual indent specs (shared with `clojure-ts-mode`). Font-locking is regex-based and extensible, with special handling for docstrings, discard macros, and character literals. The package depends only on standard Emacs libraries (`cl-lib`, `imenu`, `align`, `subr-x`) and requires Emacs 27.1+.
The LLM identified 3 files worth highlighting for reuse:
`clojure-forward-logical-sexp` and `clojure-backward-logical-sexp` provide sexp movement that skips non-logical sexps such as metadata (`^hints`) and reader macros (`#...`). These are implemented as pure buffer navigation functions using `forward-sexp` with a while loop to skip prefixes. They are isolated (no internal module imports beyond standard Emacs), handle edge cases with `save-excursion` and `ignore-errors`, and could be extracted into any Lisp-based Emacs mode that needs to treat metadata as attached to the following form.
The functions `clojure--indent-spec-to-modern` and `clojure--indent-spec-to-legacy` convert between two indent specification formats (legacy integer/:defn/positional-list and modern tuple-based ((:block N) (:inner D))). These are pure transformation functions with no side effects, well-documented, and tested. They demonstrate a clean adapter pattern that could be reused in any project needing backward-compatible format conversion.
The `clojure-align` command and supporting functions (`clojure--find-sexp-to-align`, `clojure--search-whitespace-after-next-sexp`, `clojure--position-for-alignment`) implement a vertical alignment system for Lisp forms. They handle nested maps, let bindings, cond forms, reader conditionals, and blank-line separators. The implementation uses `align-region` with a custom regexp and repeat flag, and includes pre-indentation to fix alignment of improperly indented content. This is a self-contained feature that could be ported to other structured-editing modes.