Function: clojure--indent-spec-to-legacy
clojure--indent-spec-to-legacy is a byte-compiled function defined in
clojure-mode.el.
Signature
(clojure--indent-spec-to-legacy SPEC)
Documentation
Convert a modern indent SPEC to legacy positional format.
Returns SPEC unchanged if it is not in modern format.
((:block N)) becomes N.
((:inner 0)) becomes :defn.
Complex multi-rule specs are converted to positional lists.
The legacy format will be removed in clojure-mode 6.
Source Code
;; Defined in ~/.emacs.d/elpa/clojure-mode-20260325.811/clojure-mode.el
(defun clojure--indent-spec-to-legacy (spec)
"Convert a modern indent SPEC to legacy positional format.
Returns SPEC unchanged if it is not in modern format.
\((:block N)) becomes N.
\((:inner 0)) becomes :defn.
Complex multi-rule specs are converted to positional lists.
The legacy format will be removed in clojure-mode 6."
(if (not (clojure--modern-indent-spec-p spec))
spec
;; Extract components
(let ((block-n nil)
(inner-no-idx nil) ; list of depths without position index
(inner-with-idx nil)) ; list of (depth . index) with position index
(dolist (rule spec)
(pcase rule
(`(:block ,n) (setq block-n n))
(`(:inner ,d) (push d inner-no-idx))
(`(:inner ,d ,i) (push (cons d i) inner-with-idx))))
(cond
;; Simple: only (:block N)
((and block-n (null inner-no-idx) (null inner-with-idx))
block-n)
;; Simple: only (:inner 0)
((and (null block-n) (null inner-with-idx)
(equal inner-no-idx '(0)))
:defn)
;; Complex: build positional list
(t
(let ((result (list)))
;; Position 0: block-n or first non-indexed inner
(when block-n
(setq result (list block-n)))
;; Place indexed :inner rules at their positions
(dolist (ir inner-with-idx)
(let* ((depth (car ir))
(idx (cdr ir))
(pos (+ (if block-n 1 0) idx))
(wrapped (clojure--wrap-defn depth)))
;; Pad with nil to reach position
(while (<= (length result) pos)
(setq result (append result (list nil))))
(setf (nth pos result) wrapped)))
;; Append non-indexed :inner rules as tail
;; (applies to all remaining positions)
;; Sort ascending so shallower depths come first.
(dolist (depth (sort inner-no-idx #'<))
(let ((wrapped (clojure--wrap-defn depth)))
(setq result (append result (list wrapped)))))
;; Append trailing nil if there are indexed rules
;; (so the backtracking engine sees the end of the spec)
(when inner-with-idx
(setq result (append result (list nil))))
result))))))