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.
Other specs become positional lists: an argument spec of
(:defn) is an (:inner 1) rule, ((:defn)) an (:inner 2) rule, and so
on.

The legacy format can't express everything the modern one can. Only the shallowest of several :inner rules without a position is kept, and a rule with a position replaces the others for that argument. Like in cljfmt, (:inner 0) does nothing next to a :block rule. Rules with negative numbers are ignored.

The legacy format will be removed in clojure-mode 6.

Source Code

;; Defined in ~/.emacs.d/elpa/clojure-mode-20261103.1226/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.
Other specs become positional lists: an argument spec of
\(:defn) is an (:inner 1) rule, ((:defn)) an (:inner 2) rule, and so
on.

The legacy format can't express everything the modern one can.  Only
the shallowest of several :inner rules without a position is kept, and
a rule with a position replaces the others for that argument.  Like in
cljfmt, (:inner 0) does nothing next to a :block rule.  Rules with
negative numbers are ignored.

The legacy format will be removed in clojure-mode 6."
  (if (not (clojure--modern-indent-spec-p spec))
      spec
    (let* ((block (let ((n (cadr (assq :block spec)))) (and (natnump n) n)))
           (inner (seq-filter (lambda (rule) (eq (car rule) :inner)) spec))
           (own (or block (and (member '(:inner 0) inner) :defn)))
           (depths (sort (seq-filter (lambda (depth) (> depth 0))
                                     (mapcar #'cadr (seq-remove #'cddr inner)))
                         #'<))
           (tail (and depths (clojure--wrap-defn (car depths))))
           (indexed (seq-filter (lambda (rule)
                                  (and (natnump (caddr rule)) (> (cadr rule) 0)))
                                inner)))
      (if (not (or tail indexed))
          own
        ;; The spec of the form itself, then those of its arguments.
        (let* ((args (if indexed (+ 2 (apply #'max (mapcar #'caddr indexed))) 1))
               (result (cons own (make-list args tail))))
          (pcase-dolist (`(:inner ,depth ,idx) indexed)
            (setf (nth (1+ idx) result) (clojure--wrap-defn depth)))
          result)))))