@@ -1098,7 +1098,8 @@ The message is logged to a buffer described by
1098
1098
(delete-region (point-min ) (- (point ) 1 )))
1099
1099
(goto-char (point-max ))
1100
1100
(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 )
1102
1103
(when-let ((win (get-buffer-window )))
1103
1104
(set-window-point win (point-max )))
1104
1105
(setq buffer-read-only t ))))
@@ -1134,7 +1135,16 @@ Set this to nil to prevent truncation."
1134
1135
1135
1136
(defun nrepl--expand-button (button )
1136
1137
" 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 ))))
1138
1148
1139
1149
(defun nrepl--expand-button-mouse (event )
1140
1150
" Expand the text hidden under overlay button.
@@ -1145,49 +1155,67 @@ EVENT gives the button position on window."
1145
1155
(with-selected-window window
1146
1156
(nrepl--expand-button (button-at point))))))
1147
1157
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 ))))))
1162
1176
(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 " ))))
1191
1219
1192
1220
(defun nrepl-messages-buffer-name (conn )
1193
1221
" Return the name for the message buffer matching CONN."
0 commit comments