Function: cider--parse-and-apply-locals

cider--parse-and-apply-locals is a byte-compiled function defined in cider-mode.el.

Signature

(cider--parse-and-apply-locals END &optional OUTER-LOCALS)

Documentation

Figure out local variables between point and END.

A list of these variables is set as the cider-locals text property over the code where they are in scope. Optional argument OUTER-LOCALS is used to specify local variables defined before point.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-mode.el
(defun cider--parse-and-apply-locals (end &optional outer-locals)
  "Figure out local variables between point and END.
A list of these variables is set as the `cider-locals' text property over
the code where they are in scope.
Optional argument OUTER-LOCALS is used to specify local variables defined
before point."
  (while (search-forward-regexp "(\\(ns\\_>\\|def\\|fn\\|for\\b\\|loop\\b\\|with-\\|do[a-z]+\\|\\([a-z]+-\\)?let\\b\\)"
                                end 'noerror)
    (goto-char (match-beginning 0))
    (let ((sym (match-string 1))
          ;; The regexp only captures the `def' prefix, so read the full
          ;; head symbol to tell value-binding forms apart from
          ;; function-defining ones (see the `def' branch below).
          (head (save-excursion
                  (ignore-errors
                    (forward-char 1)
                    (buffer-substring-no-properties
                     (point) (progn (forward-sexp 1) (point))))))
          (sexp-end (save-excursion
                      (or (ignore-errors (forward-sexp 1)
                                         (point))
                          end))))
      ;; #1324: Don't do dynamic font-lock in `ns' forms, they are special
      ;; macros where nothing is evaluated, so we'd get a lot of false
      ;; positives.
      (if (equal sym "ns")
          (add-text-properties (point) sexp-end '(cider-block-dynamic-font-lock t))
        (forward-char 1)
        (forward-sexp 1)
        (let ((locals (append outer-locals
                              (pcase sym
                                ;; #3657: plain value-binding `def' forms
                                ;; (`def', `defonce') have no arglist -
                                ;; reading their value as one slurps the
                                ;; whole value in as bogus locals.  Only
                                ;; function-defining forms (`defn',
                                ;; `defmacro', ...) carry an arglist.
                                ("def" (unless (member head '("def" "defonce"))
                                         (cider--read-locals-from-arglist)))
                                ((or "fn" "") (cider--read-locals-from-arglist))
                                (_ (cider--read-locals-from-bindings-vector))))))
          (add-text-properties (point) sexp-end (list 'cider-locals locals))
          (clojure-forward-logical-sexp 1)
          (cider--parse-and-apply-locals sexp-end locals)))
      (goto-char sexp-end))))