Function: clojure--legacy-spec-to-rules

clojure--legacy-spec-to-rules is a byte-compiled function defined in clojure-mode.el.

Signature

(clojure--legacy-spec-to-rules SPEC DEPTH IDX)

Documentation

Return the modern rules for a form with the legacy indent SPEC.

DEPTH is how many levels the form is below the form whose head has the spec, and IDX is the position of the argument of that form it is in, or nil for any argument.

The rules can't express everything legacy specs can. The spec of the last argument applies to all the arguments, a position inside an argument counts for nothing, and an integer below the form itself means body indentation.

Source Code

;; Defined in ~/.emacs.d/elpa/clojure-mode-20261103.1226/clojure-mode.el
(defun clojure--legacy-spec-to-rules (spec depth idx)
  "Return the modern rules for a form with the legacy indent SPEC.

DEPTH is how many levels the form is below the form whose head has the
spec, and IDX is the position of the argument of that form it is in, or
nil for any argument.

The rules can't express everything legacy specs can.  The spec of the
last argument applies to all the arguments, a position inside an
argument counts for nothing, and an integer below the form itself means
body indentation."
  (let ((inner (if idx (list :inner depth idx) (list :inner depth))))
    (pcase spec
      ((pred integerp)
       (list (if (zerop depth) (list :block spec) inner)))
      ((or :defn 'defun) (list inner))
      (`(,(and arg-spec (pred consp)))
       (clojure--legacy-spec-to-rules arg-spec (1+ depth) idx))
      (`(,own-spec . ,arg-specs)
       (let ((last-pos (1- (length arg-specs))))
         (apply #'append
                (unless (consp own-spec)
                  (clojure--legacy-spec-to-rules own-spec depth idx))
                (seq-map-indexed (lambda (arg-spec pos)
                                   (clojure--legacy-spec-to-rules
                                    arg-spec
                                    (1+ depth)
                                    (cond ((> depth 0) idx)
                                          ((< pos last-pos) pos))))
                                 arg-specs)))))))