Skip to content

Commit 01c47c7

Browse files
committed
Add support for pretty printing values in the inspector.
1 parent d6a875b commit 01c47c7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## master (unreleased)
44

5+
- [#3813](https://github.com/clojure-emacs/cider/pull/3813) Add support for pretty printing values in the inspector.
6+
57
### New features
68

79
- [#3802](https://github.com/clojure-emacs/cider/issues/3802): Inspector analytics.

cider-inspector.el

+18-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ The max depth can be also changed interactively within the inspector."
7878
:type 'boolean
7979
:package-version '(cider . "0.15.0"))
8080

81+
(defcustom cider-inspector-pretty-print nil
82+
"When true, pretty print values in the inspector."
83+
:type 'boolean
84+
:package-version '(cider . "1.18.0"))
85+
8186
(defcustom cider-inspector-skip-uninteresting t
8287
"Controls whether to skip over uninteresting values in the inspector.
8388
Only applies to navigation with `cider-inspector-prev-inspectable-object'
@@ -140,6 +145,7 @@ Can be turned to nil once the user sees and acknowledges the feature."
140145
(define-key map "n" #'cider-inspector-next-inspectable-object)
141146
(define-key map [(shift tab)] #'cider-inspector-previous-inspectable-object)
142147
(define-key map "p" #'cider-inspector-previous-inspectable-object)
148+
(define-key map "P" #'cider-inspector-toggle-pretty-print)
143149
(define-key map ":" #'cider-inspect-expr-from-inspector)
144150
(define-key map "f" #'forward-char)
145151
(define-key map "b" #'backward-char)
@@ -349,6 +355,15 @@ MAX-NESTED-DEPTH is the new value."
349355
(when (nrepl-dict-get result "value")
350356
(cider-inspector--render-value result :next-inspectable))))
351357

358+
(defun cider-inspector-toggle-pretty-print ()
359+
"Toggle the pretty printing of values in the inspector."
360+
(interactive)
361+
(let ((result (cider-nrepl-send-sync-request
362+
`("op" "inspect-toggle-pretty-print")
363+
(cider-current-repl))))
364+
(when (nrepl-dict-get result "value")
365+
(cider-inspector--render-value result))))
366+
352367
(defun cider-inspector-toggle-view-mode ()
353368
"Toggle the view mode of the inspector between normal and object view mode."
354369
(interactive)
@@ -508,7 +523,9 @@ MAX-COLL-SIZE if non nil."
508523
,@(when cider-inspector-max-nested-depth
509524
`("max-nested-depth" ,cider-inspector-max-nested-depth))
510525
,@(when cider-inspector-display-analytics-hint
511-
`("display-analytics-hint" "true"))))
526+
`("display-analytics-hint" "true"))
527+
,@(when cider-inspector-pretty-print
528+
`("pretty-print" "true"))))
512529
(cider-nrepl-send-sync-request (cider-current-repl))))
513530

514531
(declare-function cider-set-buffer-ns "cider-mode")

doc/modules/ROOT/pages/debugging/inspector.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ You'll have access to additional keybindings in the inspector buffer
8181
| Switch the rendering of the current value between `:normal`, `:table`, and
8282
`:object` view modes. In `:table` mode, render the value as a table (only supported for sequences of maps or tuples). In `:object` mode, any value is rendered as a plain Java object (by displaying its fields) instead of custom rendering rules that the Inspector applies in `:normal` mode.
8383

84+
| kbd:[P]
85+
| `cider-inspector-toggle-pretty-print`
86+
| Toggle the pretty printing of values in the inspector. You can set the `cider-inspector-pretty-print` customization option to `t`, if you always want values to be be pretty printed.
87+
8488
| kbd:[d]
8589
| `cider-inspector-def-current-val`
8690
| Defines a var in the REPL namespace with current inspector value. If you tend to always choose the same name(s), you may want to set the `cider-inspector-preferred-var-names` customization option.

0 commit comments

Comments
 (0)