Skip to content

Commit 6d3385e

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

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

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

33
## master (unreleased)
44

5+
- 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

+17-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ Can be turned to nil once the user sees and acknowledges the feature."
9797
:type 'boolean
9898
:package-version '(cider . "1.18.0"))
9999

100+
(defcustom cider-inspector-pretty-print nil
101+
"When true, pretty print values in the inspector."
102+
:type 'boolean
103+
:package-version '(cider . "1.18.0"))
104+
100105
(defvar cider-inspector-uninteresting-regexp
101106
(concat "nil" ; nils are not interesting
102107
"\\|:" clojure--sym-regexp ; nor keywords
@@ -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,14 @@ 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 ((pretty-print-p (not cider-inspector-pretty-print)))
362+
(setq cider-inspector-pretty-print pretty-print-p)
363+
(cider-inspector--refresh-with-opts "pretty-print" (if pretty-print-p "true" "false"))
364+
(message "Pretty printing in the inspector %s." (if pretty-print-p "enabled" "disabled"))))
365+
352366
(defun cider-inspector-toggle-view-mode ()
353367
"Toggle the view mode of the inspector between normal and object view mode."
354368
(interactive)
@@ -508,7 +522,9 @@ MAX-COLL-SIZE if non nil."
508522
,@(when cider-inspector-max-nested-depth
509523
`("max-nested-depth" ,cider-inspector-max-nested-depth))
510524
,@(when cider-inspector-display-analytics-hint
511-
`("display-analytics-hint" "true"))))
525+
`("display-analytics-hint" "true"))
526+
,@(when cider-inspector-pretty-print
527+
`("pretty-print" "true"))))
512528
(cider-nrepl-send-sync-request (cider-current-repl))))
513529

514530
(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.
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)