Function: nrepl-log-message

nrepl-log-message is a byte-compiled function defined in nrepl-client.el.

Signature

(nrepl-log-message MSG TYPE)

Documentation

Log the nREPL MSG.

TYPE is either request or response. The message is logged to a buffer described by nrepl-message-buffer-name-template.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/nrepl-client.el
(defun nrepl-log-message (msg type)
  "Log the nREPL MSG.
TYPE is either request or response.  The message is logged to a buffer
described by `nrepl-message-buffer-name-template'."
  (when nrepl-log-messages
    ;; Prepend a time-stamp pair to a fresh head, sharing the original
    ;; cdr as the tail.  Using `nrepl-plist-put' here would mutate the
    ;; live message dict, so downstream response handlers would see an
    ;; unexpected "time-stamp" key appearing on the response they got.
    (setq msg (cons (car msg)
                    (cons "time-stamp"
                          (cons (format-time-string "%Y-%m-%0d %H:%M:%S.%N")
                                (cdr msg)))))
    (let ((log-buffer (nrepl-messages-buffer (current-buffer))))
      (with-current-buffer log-buffer
        (setq buffer-read-only nil)
        ;; Snapshot which windows were already at end-of-buffer before we
        ;; insert, so we only auto-follow those.  Windows the user has
        ;; scrolled back to read history are left where they are.
        (let ((following (seq-filter
                          (lambda (w) (= (window-point w) (point-max)))
                          (get-buffer-window-list log-buffer nil t))))
          (when (> (buffer-size) nrepl-message-buffer-max-size)
            (goto-char (/ (buffer-size) nrepl-message-buffer-reduce-denominator))
            (re-search-forward "^(" nil t)
            (delete-region (point-min) (- (point) 1)))
          (goto-char (point-max))
          (nrepl-log-pp-object (nrepl-decorate-msg msg type)
                               (nrepl-log--message-face (nrepl-plist-get (cdr msg) "id"))
                               t)
          (dolist (w following)
            (set-window-point w (point-max))))
        (setq buffer-read-only t)))))