Function: cider-trace--render-event

cider-trace--render-event is a byte-compiled function defined in cider-tracing.el.

Signature

(cider-trace--render-event EVENT)

Documentation

Append the trace EVENT to the current buffer, following the tail.

A call and its return are paired by their shared id, so the lines nested between them become a foldable region (see cider-trace-toggle-fold). The operator of each call is a button that jumps to its definition.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260920.725/cider-tracing.el
(defun cider-trace--render-event (event)
  "Append the trace EVENT to the current buffer, following the tail.
A call and its return are paired by their shared `id', so the lines
nested between them become a foldable region (see `cider-trace-toggle-fold').
The operator of each call is a button that jumps to its definition."
  (unless cider-trace--open-calls
    (setq cider-trace--open-calls (make-hash-table :test 'equal)
          cider-trace--folds (make-hash-table :test 'equal)))
  (nrepl-dbind-response event (id phase name depth args value)
    (let ((inhibit-read-only t)
          (indent (cider-trace--indent depth))
          (at-end (= (point) (point-max))))
      (save-excursion
        (goto-char (point-max))
        (pcase phase
          ("call"
           (let ((line-start (point)))
             (insert indent "(")
             (insert-text-button name
                                 'cider-trace-fn name
                                 'action #'cider-trace--find-var-button
                                 'face 'font-lock-function-name-face
                                 'mouse-face 'highlight
                                 'follow-link t
                                 'help-echo "mouse-1: jump to definition")
             (when args
               (insert " " (cider-font-lock-as-clojure
                            (mapconcat #'identity args " "))))
             (insert ")\n")
             (when id
               ;; tag the call line so fold/jump commands on it can find their
               ;; target, and remember the call line and where its children begin
               (put-text-property line-start (point) 'cider-trace-call-id id)
               (put-text-property line-start (point) 'cider-trace-fn name)
               (puthash id (cons (copy-marker line-start) (copy-marker (point)))
                        cider-trace--open-calls))))
          ("return"
           (let* ((entry (and id (gethash id cider-trace--open-calls)))
                  (line-start (car entry))
                  (children-start (cdr entry))
                  (children-end (point-marker)))
             (when id (remhash id cider-trace--open-calls))
             (insert indent "└─→ "
                     (cider-font-lock-as-clojure (or value "nil"))
                     "\n")
             ;; if the call had nested children, make that block foldable and
             ;; mark its call line as interactive (hover + click to fold)
             (when (and children-start (< children-start children-end))
               (let ((ov (make-overlay children-start children-end)))
                 (overlay-put ov 'evaporate t)
                 (puthash id ov cider-trace--folds))
               (put-text-property line-start children-start 'mouse-face 'highlight)
               (put-text-property line-start children-start
                                  'keymap cider-trace--fold-line-map))))))
      (when at-end (goto-char (point-max))))))