Skip to content

Commit 1d7648c

Browse files
committed
Dump decoding errors to a dedicated nREPL error buffer
1 parent 817d37e commit 1d7648c

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

nrepl-client.el

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
182182
;;; nREPL Buffer Names
183183

184184
(defconst nrepl-message-buffer-name-template "*nrepl-messages %s*")
185+
(defconst nrepl-error-buffer-name "*nrepl-error*")
185186
(defconst nrepl-repl-buffer-name-template "*cider-repl%s*")
186187
(defconst nrepl-connection-buffer-name-template "*nrepl-connection%s*")
187188
(defconst nrepl-server-buffer-name-template "*nrepl-server%s*")
@@ -493,11 +494,11 @@ object is a root list or dict."
493494
;; else, throw a quiet error
494495
(t
495496
(message "Invalid bencode message detected. See %s buffer."
496-
nrepl-message-buffer-name-template)
497-
(nrepl-log-message
497+
nrepl-error-buffer-name)
498+
(nrepl-log-error
498499
(format "Decoder error at position %d (`%s'):"
499500
(point) (buffer-substring (point) (min (+ (point) 10) (point-max)))))
500-
(nrepl-log-message (buffer-string))
501+
(nrepl-log-error (buffer-string))
501502
(ding)
502503
;; Ensure loop break and clean queues' states in nrepl-bdecode:
503504
(goto-char (point-max))
@@ -1272,6 +1273,26 @@ The default buffer name is *nrepl-messages session*."
12721273
(nrepl-messages-mode)
12731274
buffer)))))
12741275

1276+
(defun nrepl-error-buffer ()
1277+
"Return or create the buffer.
1278+
The default buffer name is *nrepl-error*."
1279+
(or (get-buffer nrepl-error-buffer-name)
1280+
(let ((buffer (get-buffer-create nrepl-error-buffer-name)))
1281+
(with-current-buffer buffer
1282+
(buffer-disable-undo)
1283+
(fundamental-mode)
1284+
buffer))))
1285+
1286+
(defun nrepl-log-error (msg)
1287+
"Log the given MSG to the buffer given by `nrepl-error-buffer'."
1288+
(with-current-buffer (nrepl-error-buffer)
1289+
(setq buffer-read-only nil)
1290+
(goto-char (point-max))
1291+
(insert msg)
1292+
(when-let ((win (get-buffer-window)))
1293+
(set-window-point win (point-max)))
1294+
(setq buffer-read-only t)))
1295+
12751296
(defun nrepl-create-client-buffer-default (endpoint)
12761297
"Create an nREPL client process buffer.
12771298
ENDPOINT is a plist returned by `nrepl-connect'."

0 commit comments

Comments
 (0)