Function: cider--insert-in-comment

cider--insert-in-comment is a byte-compiled function defined in cider-eval.el.

Signature

(cider--insert-in-comment FORM)

Documentation

Append FORM to the namespace's rich comment block.

Create a comment block at the end of the buffer when there is none. Return a cons (BEG . END) of the inserted form's bounds; END is a marker so it tracks later insertions (the eval-to-comment handler inserts the result there).

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-eval.el
(defun cider--insert-in-comment (form)
  "Append FORM to the namespace's rich `comment' block.
Create a `comment' block at the end of the buffer when there is none.  Return
a cons (BEG . END) of the inserted form's bounds; END is a marker so it tracks
later insertions (the eval-to-comment handler inserts the result there)."
  (let ((trimmed (string-trim form))
        (bounds (cider--last-comment-form-bounds))
        (beg (make-marker))
        (end (make-marker)))
    (if bounds
        ;; append just before the closing paren of the existing block,
        ;; preserving whether that paren hugs the last form or sits alone
        ;; (the marker tracks the closing paren across the insertion so the
        ;; whole, grown block gets re-indented)
        (let ((block-end (copy-marker (cdr bounds)))
              (after-header (save-excursion
                              (goto-char (car bounds))
                              (forward-char)   ; past the opening paren
                              (forward-sexp)   ; past the `comment' symbol
                              (point))))
          (goto-char (1- (cdr bounds)))
          (skip-chars-backward " \t\n")
          ;; separate entries with a blank line for readability, but don't add
          ;; one right after the `comment' header (i.e. when the block is empty)
          (insert (if (> (point) after-header) "\n\n" "\n"))
          (set-marker beg (point))
          (insert trimmed)
          (set-marker end (point))
          ;; Integer bounds, not the marker: see the `indent-region' note in
          ;; `cider-macrostep--expand-region' (Emacs 30.1 tree-sitter bug).
          (indent-region (car bounds) (marker-position block-end)))
      ;; no block yet: create one at the end of the buffer
      (goto-char (point-max))
      (skip-chars-backward " \t\n")
      (delete-region (point) (point-max))
      (insert "\n\n")
      (let ((block-start (point)))
        (insert "(comment\n")
        (set-marker beg (point))
        (insert trimmed ")")
        (set-marker end (1- (point)))
        (indent-region block-start (point))))
    (cons (marker-position beg) end)))