Skip to content

Add support for pretty printing values in the inspector. #3813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

- [#3813](https://github.com/clojure-emacs/cider/pull/3813) Add support for pretty printing values in the inspector.
- [#3802](https://github.com/clojure-emacs/cider/issues/3802): Inspector analytics.
- [#3802](https://github.com/clojure-emacs/cider/issues/3802): Inspector table view-mode.
- [orchard#320](https://github.com/clojure-emacs/orchard/pull/320): Info: recognize printed Java classes/methods and munged Clojure functions in stacktrace outputs.
Expand Down
19 changes: 18 additions & 1 deletion cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ The max depth can be also changed interactively within the inspector."
:type 'boolean
:package-version '(cider . "0.15.0"))

(defcustom cider-inspector-pretty-print nil
"When true, pretty print values in the inspector."
:type 'boolean
:package-version '(cider . "1.18.0"))

(defcustom cider-inspector-skip-uninteresting t
"Controls whether to skip over uninteresting values in the inspector.
Only applies to navigation with `cider-inspector-prev-inspectable-object'
Expand Down Expand Up @@ -140,6 +145,7 @@ Can be turned to nil once the user sees and acknowledges the feature."
(define-key map "n" #'cider-inspector-next-inspectable-object)
(define-key map [(shift tab)] #'cider-inspector-previous-inspectable-object)
(define-key map "p" #'cider-inspector-previous-inspectable-object)
(define-key map "P" #'cider-inspector-toggle-pretty-print)
(define-key map ":" #'cider-inspect-expr-from-inspector)
(define-key map "f" #'forward-char)
(define-key map "b" #'backward-char)
Expand Down Expand Up @@ -349,6 +355,15 @@ MAX-NESTED-DEPTH is the new value."
(when (nrepl-dict-get result "value")
(cider-inspector--render-value result :next-inspectable))))

(defun cider-inspector-toggle-pretty-print ()
"Toggle the pretty printing of values in the inspector."
(interactive)
(let ((result (cider-nrepl-send-sync-request
`("op" "inspect-toggle-pretty-print")
(cider-current-repl))))
(when (nrepl-dict-get result "value")
(cider-inspector--render-value result))))

(defun cider-inspector-toggle-view-mode ()
"Toggle the view mode of the inspector between normal and object view mode."
(interactive)
Expand Down Expand Up @@ -508,7 +523,9 @@ MAX-COLL-SIZE if non nil."
,@(when cider-inspector-max-nested-depth
`("max-nested-depth" ,cider-inspector-max-nested-depth))
,@(when cider-inspector-display-analytics-hint
`("display-analytics-hint" "true"))))
`("display-analytics-hint" "true"))
,@(when cider-inspector-pretty-print
`("pretty-print" "true"))))
(cider-nrepl-send-sync-request (cider-current-repl))))

(declare-function cider-set-buffer-ns "cider-mode")
Expand Down
8 changes: 8 additions & 0 deletions doc/modules/ROOT/pages/debugging/inspector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ You'll have access to additional keybindings in the inspector buffer
| Switch the rendering of the current value between `:normal`, `:table`, and
`: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.

| kbd:[P]
| `cider-inspector-toggle-pretty-print`
| 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.

| kbd:[d]
| `cider-inspector-def-current-val`
| 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.
Expand Down Expand Up @@ -130,6 +134,10 @@ listed in the table above.
If you enable `cider-inspector-fill-frame`, the inspector window fills its
frame.

You can toggle the pretty printing of values in the inspector with
kbd:[P] and customize their initial presentation by adjusting the
`cider-inspector-pretty-print` customization option.

When you define a var using kbd:[d], a var name can be suggested (default none).
You can customize this value via the `cider-inspector-preferred-var-names`
configuration option. Even after setting it, you are free to choose new names on
Expand Down
Loading