Function: cider-macrostep--expand-region

cider-macrostep--expand-region is a byte-compiled function defined in cider-macrostep.el.

Signature

(cider-macrostep--expand-region BEG END EXPANSION)

Documentation

Replace BEG..END with EXPANSION, recording the original text for collapse.

Enter cider-macrostep-mode(var)/cider-macrostep-mode(fun) when it isn't already active.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-macrostep.el
(defun cider-macrostep--expand-region (beg end expansion)
  "Replace BEG..END with EXPANSION, recording the original text for collapse.
Enter `cider-macrostep-mode' when it isn't already active."
  (let ((original (buffer-substring-no-properties beg end))
        (parent (cider-macrostep--overlay-at beg)))
    (unless cider-macrostep-mode
      (cider-macrostep-mode 1))
    (with-silent-modifications
      (let ((inhibit-read-only t))
        (atomic-change-group
          (goto-char beg)
          (delete-region beg end)
          (let ((ins-beg (point-marker))
                (ins-end (copy-marker (point) t)))
            (insert expansion)
            ;; Pass integer positions, not the markers: `indent-region'
            ;; forwards its args to `treesit-indent-region', and Emacs 30.1's
            ;; tree-sitter chokes on marker bounds (bug in `treesit-query-capture'
            ;; via the markdown-inline range update clojure-ts-mode installs).
            (indent-region (marker-position ins-beg) (marker-position ins-end))
            (let ((ov (make-overlay ins-beg ins-end)))
              (overlay-put ov 'cider-macrostep-original-text original)
              (overlay-put ov 'priority (if parent
                                            (1+ (overlay-get parent 'priority))
                                          1))
              (overlay-put ov 'face 'cider-macrostep-expansion-face)
              (push ov cider-macrostep--overlays))
            (goto-char ins-beg)
            (when cider-macroexpansion-highlight-expansion
              (pulse-momentary-highlight-region ins-beg ins-end))))))))