branch: elpa/cider commit 600aa6424613df3636478f8a0c4cffa4b96a5073 Author: Roman Scherer <ro...@burningswell.com> Commit: Oleksandr Yakushev <a...@bytopia.org>
Add support for pretty printing values in the inspector. --- CHANGELOG.md | 1 + cider-inspector.el | 19 ++++++++++++++++++- doc/modules/ROOT/pages/debugging/inspector.adoc | 8 ++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d423f8b7..8be4f326b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/cider-inspector.el b/cider-inspector.el index 705dd8ccb3..75a5355390 100644 --- a/cider-inspector.el +++ b/cider-inspector.el @@ -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' @@ -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) @@ -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) @@ -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") diff --git a/doc/modules/ROOT/pages/debugging/inspector.adoc b/doc/modules/ROOT/pages/debugging/inspector.adoc index f6b1298863..2b5430cb2f 100644 --- a/doc/modules/ROOT/pages/debugging/inspector.adoc +++ b/doc/modules/ROOT/pages/debugging/inspector.adoc @@ -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. @@ -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