Skip to content

Commit 08f48fb

Browse files
committed
Merge pull request #792 from vitoshka/better-message
Improve readability and visibility of *nrepl-messages* buffer
2 parents 5763280 + b0fb842 commit 08f48fb

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

nrepl-client.el

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ Return new dict. Dict is modified by side effects."
273273
collect (car l))
274274
(error "Not a nREPL dict.")))
275275

276-
277276
(defun nrepl--cons (car list-or-dict)
278277
"Generic cons of CAR to LIST-OR-DICT."
279278
(if (eq (car list-or-dict) 'dict)
@@ -474,7 +473,7 @@ First we check the callbacks of pending requests. If no callback was found,
474473
we check the completed requests, since responses could be received even for
475474
older requests with \"done\" status."
476475
(nrepl-dbind-response response (id)
477-
(nrepl-log-message response)
476+
(nrepl-log-message (cons '<- (cdr response)))
478477
(let ((callback (or (gethash id nrepl-pending-requests)
479478
(gethash id nrepl-completed-requests))))
480479
(if callback
@@ -698,7 +697,7 @@ REQUEST is a pair list of the form (\"op\" \"operation\" \"par1-name\"
698697
(let* ((request-id (nrepl-next-request-id))
699698
(request (append (list 'dict "id" request-id) request))
700699
(message (nrepl-bencode request)))
701-
(nrepl-log-message request)
700+
(nrepl-log-message (cons '---> (cdr request)))
702701
(with-current-buffer (nrepl-current-connection-buffer)
703702
(puthash request-id callback nrepl-pending-requests)
704703
(process-send-string nil message))))
@@ -948,21 +947,37 @@ number of buffer shrinking operations.")
948947
(re-search-forward "^(" nil t)
949948
(delete-region (point-min) (- (point) 1)))
950949
(goto-char (point-max))
951-
(nrepl--pp msg (current-buffer)))))
952-
953-
(defun nrepl--pp (object &optional stream)
954-
"Pretty print nREPL objects."
955-
(let ((stream (or stream standard-output)))
956-
(if (not (nrepl-dict-p object))
957-
(pp object stream)
958-
(princ "(dict\n" stream)
959-
(cl-loop for l on (cdr object) by #'cddr
960-
do (princ (format " %s\t%s%s"
961-
(car l) (pp-to-string (cadr l))
962-
(if (cddr l) "\n" ""))
963-
stream))
964-
(princ ")\n" stream))
965-
(if (stringp object) (princ "\n" stream))))
950+
(nrepl--pp msg)
951+
(-when-let (win (get-buffer-window))
952+
(set-window-point win (point-max))))))
953+
954+
(defvar nrepl--message-colors
955+
'("red" "brown" "coral" "orange" "green" "deep sky blue" "blue" "dark violet")
956+
"Colors used in `nrepl-messages-buffer'.")
957+
958+
(defun nrepl--pp (object)
959+
"Pretty print nREPL OBJECT."
960+
(if (not (and (listp object)
961+
(memq (car object) '(<- ---> dict))))
962+
(progn (pp object (current-buffer))
963+
(unless (listp object) (insert "\n")))
964+
(let* ((id (lax-plist-get (cdr object) "id"))
965+
(id (and id (mod (string-to-number id)
966+
(length nrepl--message-colors))))
967+
(head (format "(%s" (car object)))
968+
(foreground (and id (nth id nrepl--message-colors))))
969+
(cl-flet ((color (str)
970+
(propertize str 'face `(:weight ultra-bold :foreground ,foreground))))
971+
(insert (color head))
972+
(let ((indent (+ 2 (- (current-column) (length head)))))
973+
(if (null (cdr object))
974+
(insert ")\n")
975+
(insert "\n")
976+
(cl-loop for l on (cdr object) by #'cddr
977+
do (let ((str (format "%s%s " (make-string indent ? ) (car l))))
978+
(insert str)
979+
(nrepl--pp (cadr l))))
980+
(insert (color (format "%s)\n" (make-string (- indent 2) ? ))))))))))
966981

967982
(defun nrepl-messages-buffer ()
968983
"Return or create the buffer given by `nrepl-message-buffer-name'.

0 commit comments

Comments
 (0)