Skip to content

Commit f28ebb7

Browse files
vspinubbatsov
authored andcommitted
[Fix #1859] In message log insert large objects on request only
1 parent 111d957 commit f28ebb7

File tree

2 files changed

+73
-44
lines changed

2 files changed

+73
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ within the scope of your current Emacs session.
2626
* Add option to define exclusions for injected dependecies. Fixes [#1824](https://github.com/clojure-emacs/cider/issues/1824): Can no longer jack-in to an inherited clojure version.
2727
* [#1820](https://github.com/clojure-emacs/cider/issues/1820): Don't try to display eldoc in EDN buffers.
2828
* [#1823](https://github.com/clojure-emacs/cider/issues/1823): Fix column location metadata set by interactive evaluation.
29+
* [#1859](https://github.com/clojure-emacs/cider/issues/1859): Remove the overhead of nREPL message log.
2930

3031
## 0.13.0 (2016-07-25)
3132

nrepl-client.el

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ The message is logged to a buffer described by
10981098
(delete-region (point-min) (- (point) 1)))
10991099
(goto-char (point-max))
11001100
(nrepl--pp (nrepl-decorate-msg msg type)
1101-
(nrepl--message-color (lax-plist-get (cdr msg) "id")))
1101+
(nrepl--message-color (lax-plist-get (cdr msg) "id"))
1102+
t)
11021103
(when-let ((win (get-buffer-window)))
11031104
(set-window-point win (point-max)))
11041105
(setq buffer-read-only t))))
@@ -1134,7 +1135,16 @@ Set this to nil to prevent truncation."
11341135

11351136
(defun nrepl--expand-button (button)
11361137
"Expand the text hidden under overlay BUTTON."
1137-
(delete-overlay button))
1138+
(let* ((start (overlay-start button))
1139+
(end (overlay-end button))
1140+
(obj (overlay-get button :nrepl-object))
1141+
(inhibit-read-only t))
1142+
(save-excursion
1143+
(goto-char start)
1144+
(delete-overlay button)
1145+
(delete-region start end)
1146+
(nrepl--pp obj)
1147+
(delete-char -1))))
11381148

11391149
(defun nrepl--expand-button-mouse (event)
11401150
"Expand the text hidden under overlay button.
@@ -1145,49 +1155,67 @@ EVENT gives the button position on window."
11451155
(with-selected-window window
11461156
(nrepl--expand-button (button-at point))))))
11471157

1148-
(define-button-type 'nrepl--collapsed-dict
1149-
'display "..."
1150-
'action #'nrepl--expand-button
1151-
'face 'link
1152-
'help-echo "RET: Expand dict.")
1153-
1154-
(defun nrepl--pp (object &optional foreground)
1155-
"Pretty print nREPL OBJECT, delimited using FOREGROUND."
1156-
(if (not (and (listp object)
1157-
(memq (car object) '(<-- --> dict))))
1158-
(progn (when (stringp object)
1159-
(setq object (substring-no-properties object)))
1160-
(pp object (current-buffer))
1161-
(unless (listp object) (insert "\n")))
1158+
(defun nrepl--insert-button (label object)
1159+
"Insert button with LABEL and :nrepl-object property as OBJECT."
1160+
(insert-button label
1161+
:nrepl-object object
1162+
'action #'nrepl--expand-button
1163+
'face 'link
1164+
'help-echo "RET: Expand object."
1165+
;; Workaround for bug#1568.
1166+
'local-map '(keymap (mouse-1 . nrepl--expand-button-mouse)))
1167+
(insert "\n"))
1168+
1169+
(defun nrepl--pp-listlike (object &optional foreground button)
1170+
"Pretty print nREPL list like OBJECT.
1171+
FOREGROUND and BUTTON are as in `nrepl--pp'."
1172+
(cl-flet ((color (str)
1173+
(propertize str 'face
1174+
(append '(:weight ultra-bold)
1175+
(when foreground `(:foreground ,foreground))))))
11621176
(let ((head (format "(%s" (car object))))
1163-
(cl-flet ((color (str)
1164-
(propertize str 'face (append '(:weight ultra-bold)
1165-
(when foreground `(:foreground ,foreground))))))
1166-
(insert (color head))
1167-
(let ((indent (+ 2 (- (current-column) (length head))))
1168-
(l (point)))
1169-
(if (null (cdr object))
1170-
(insert ")\n")
1171-
(insert " \n")
1172-
(cl-loop for l on (cdr object) by #'cddr
1173-
do (let ((str (format "%s%s " (make-string indent ?\s)
1174-
(propertize (car l) 'face
1175-
;; Only highlight top-level keys.
1176-
(unless (eq (car object) 'dict)
1177-
'font-lock-keyword-face)))))
1178-
(insert str)
1179-
(nrepl--pp (cadr l))))
1180-
(when (eq (car object) 'dict)
1181-
(delete-char -1)
1182-
(let ((truncate-lines t))
1183-
(when (and nrepl-dict-max-message-size
1184-
(> (count-screen-lines l (point) t)
1185-
nrepl-dict-max-message-size))
1186-
(make-button (1+ l) (point)
1187-
:type 'nrepl--collapsed-dict
1188-
;; Workaround for bug#1568.
1189-
'local-map '(keymap (mouse-1 . nrepl--expand-button-mouse))))))
1190-
(insert (color ")\n"))))))))
1177+
(insert (color head))
1178+
(let ((indent (+ 2 (- (current-column) (length head))))
1179+
(l (point)))
1180+
(if (null (cdr object))
1181+
(insert ")\n")
1182+
(insert " \n")
1183+
(cl-loop for l on (cdr object) by #'cddr
1184+
do (let ((str (format "%s%s " (make-string indent ?\s)
1185+
(propertize (car l) 'face
1186+
;; Only highlight top-level keys.
1187+
(unless (eq (car object) 'dict)
1188+
'font-lock-keyword-face)))))
1189+
(insert str)
1190+
(nrepl--pp (cadr l) nil button)))
1191+
(when (eq (car object) 'dict)
1192+
(delete-char -1))
1193+
(insert (color ")\n")))))))
1194+
1195+
(defun nrepl--pp (object &optional foreground button)
1196+
"Pretty print nREPL OBJECT, delimited using FOREGROUND.
1197+
If BUTTON is non-nil, try making a button from OBJECT instead of inserting
1198+
it into the buffer."
1199+
(if-let ((head (car-safe object)))
1200+
;; listlike objects
1201+
(cond
1202+
((memq head '(<-- -->))
1203+
(nrepl--pp-listlike object foreground button))
1204+
((eq head 'dict)
1205+
(if (and button (> (length object) 1))
1206+
(nrepl--insert-button "(dict ...)" object)
1207+
(nrepl--pp-listlike object foreground button)))
1208+
(t
1209+
(if (and button (> (length object) 10))
1210+
(nrepl--insert-button (format "(%s ...)" (prin1-to-string head)) object)
1211+
(pp object (current-buffer)))))
1212+
;; non-list objects
1213+
(if (stringp object)
1214+
(if (and button (> (length object) 80))
1215+
(nrepl--insert-button (format "\"%s...\"" (substring object 0 40)) object)
1216+
(insert (prin1-to-string object) "\n"))
1217+
(pp object (current-buffer))
1218+
(insert "\n"))))
11911219

11921220
(defun nrepl-messages-buffer-name (conn)
11931221
"Return the name for the message buffer matching CONN."

0 commit comments

Comments
 (0)