Skip to content

Commit c6a49d5

Browse files
vspinubbatsov
authored andcommitted
New interactive commands nrepl-log-expand-button/all-buttons
1 parent e4ab03e commit c6a49d5

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ within the scope of your current Emacs session.
1414
* [#1748](https://github.com/clojure-emacs/cider/issues/1748): Add new interactive command `cider-pprint-eval-last-sexp-to-repl`.
1515
* [#1789](https://github.com/clojure-emacs/cider/issues/1789): Make it easy to change the connection of the cider-scratch buffer from the mode's menu.
1616
* New interactive command `cider-toggle-buffer-connection`.
17+
* [#1861](https://github.com/clojure-emacs/cider/issues/1861): New interactive commands in message log buffer `nrepl-log-expand-button` and `nrepl-log-expand-all-buttons`.
1718

1819
### Changes
1920

@@ -28,6 +29,7 @@ within the scope of your current Emacs session.
2829
* [#1823](https://github.com/clojure-emacs/cider/issues/1823): Fix column location metadata set by interactive evaluation.
2930
* [#1859](https://github.com/clojure-emacs/cider/issues/1859): Make nREPL message log much faster. `nrepl-dict-max-message-size` custom variable was removed.
3031

32+
3133
## 0.13.0 (2016-07-25)
3234

3335
### New Features

nrepl-client.el

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,8 @@ operations.")
10611061
(define-key map (kbd "n") #'next-line)
10621062
(define-key map (kbd "p") #'previous-line)
10631063
(define-key map (kbd "TAB") #'forward-button)
1064+
(define-key map (kbd "e") #'nrepl-log-expand-button)
1065+
(define-key map (kbd "E") #'nrepl-log-expand-all-buttons)
10641066
(define-key map (kbd "<backtab>") #'backward-button)
10651067
map))
10661068

@@ -1120,26 +1122,35 @@ This in effect enables or disables the logging of nREPL messages."
11201122
:type '(repeat color)
11211123
:group 'nrepl)
11221124

1123-
(defun nrepl--message-color (id)
1124-
"Return the color to use when pretty-printing the nREPL message with ID.
1125-
If ID is nil, return nil."
1126-
(when id
1127-
(thread-first (string-to-number id)
1128-
(mod (length nrepl-message-colors))
1129-
(nth nrepl-message-colors))))
1130-
1131-
(defun nrepl--expand-button (button)
1132-
"Expand the text hidden under overlay BUTTON."
1133-
(let* ((start (overlay-start button))
1134-
(end (overlay-end button))
1135-
(obj (overlay-get button :nrepl-object))
1136-
(inhibit-read-only t))
1125+
(defun nrepl-log-expand-button (&optional button)
1126+
"Expand the objects hidden in BUTTON's :nrepl-object property.
1127+
BUTTON defaults the button at point."
1128+
(interactive)
1129+
(if-let ((button (or button (button-at (point)))))
1130+
(let* ((start (overlay-start button))
1131+
(end (overlay-end button))
1132+
(obj (overlay-get button :nrepl-object))
1133+
(inhibit-read-only t))
1134+
(save-excursion
1135+
(goto-char start)
1136+
(delete-overlay button)
1137+
(delete-region start end)
1138+
(nrepl--pp obj)
1139+
(delete-char -1)))
1140+
(error "No button at point")))
1141+
1142+
(defun nrepl-log-expand-all-buttons ()
1143+
"Expand all buttons in nREPL log buffer."
1144+
(interactive)
1145+
(if (not (eq major-mode 'nrepl-messages-mode))
1146+
(user-error "Not in a `nrepl-messages-mode'")
11371147
(save-excursion
1138-
(goto-char start)
1139-
(delete-overlay button)
1140-
(delete-region start end)
1141-
(nrepl--pp obj)
1142-
(delete-char -1))))
1148+
(let* ((pos (point-min))
1149+
(button (next-button pos)))
1150+
(while button
1151+
(setq pos (overlay-start button))
1152+
(nrepl-log-expand-button button)
1153+
(setq button (next-button pos)))))))
11431154

11441155
(defun nrepl--expand-button-mouse (event)
11451156
"Expand the text hidden under overlay button.
@@ -1148,19 +1159,27 @@ EVENT gives the button position on window."
11481159
(pcase (elt event 1)
11491160
(`(,window ,_ ,_ ,_ ,_ ,point . ,_)
11501161
(with-selected-window window
1151-
(nrepl--expand-button (button-at point))))))
1162+
(nrepl-log-expand-button (button-at point))))))
11521163

1153-
(defun nrepl--insert-button (label object)
1164+
(defun nrepl-log-insert-button (label object)
11541165
"Insert button with LABEL and :nrepl-object property as OBJECT."
11551166
(insert-button label
11561167
:nrepl-object object
1157-
'action #'nrepl--expand-button
1168+
'action #'nrepl-log-expand-button
11581169
'face 'link
11591170
'help-echo "RET: Expand object."
11601171
;; Workaround for bug#1568.
11611172
'local-map '(keymap (mouse-1 . nrepl--expand-button-mouse)))
11621173
(insert "\n"))
11631174

1175+
(defun nrepl--message-color (id)
1176+
"Return the color to use when pretty-printing the nREPL message with ID.
1177+
If ID is nil, return nil."
1178+
(when id
1179+
(thread-first (string-to-number id)
1180+
(mod (length nrepl-message-colors))
1181+
(nth nrepl-message-colors))))
1182+
11641183
(defun nrepl--pp-listlike (object &optional foreground button)
11651184
"Pretty print nREPL list like OBJECT.
11661185
FOREGROUND and BUTTON are as in `nrepl--pp'."
@@ -1197,23 +1216,23 @@ it into the buffer."
11971216
(if-let ((head (car-safe object)))
11981217
;; list-like objects
11991218
(cond
1200-
;; top level dicts (always unfolded)
1219+
;; top level dicts (always expanded)
12011220
((memq head '(<-- -->))
12021221
(nrepl--pp-listlike object foreground button))
12031222
;; inner dicts
12041223
((eq head 'dict)
12051224
(if (and button (> (length object) min-dict-fold-size))
1206-
(nrepl--insert-button "(dict ...)" object)
1225+
(nrepl-log-insert-button "(dict ...)" object)
12071226
(nrepl--pp-listlike object foreground button)))
12081227
;; lists
12091228
(t
12101229
(if (and button (> (length object) min-list-fold-size))
1211-
(nrepl--insert-button (format "(%s ...)" (prin1-to-string head)) object)
1230+
(nrepl-log-insert-button (format "(%s ...)" (prin1-to-string head)) object)
12121231
(pp object (current-buffer)))))
12131232
;; non-list objects
12141233
(if (stringp object)
12151234
(if (and button (> (length object) min-string-fold-size))
1216-
(nrepl--insert-button (format "\"%s...\"" (substring object 0 min-string-fold-size)) object)
1235+
(nrepl-log-insert-button (format "\"%s...\"" (substring object 0 min-string-fold-size)) object)
12171236
(insert (prin1-to-string object) "\n"))
12181237
(pp object (current-buffer))
12191238
(insert "\n")))))

0 commit comments

Comments
 (0)