Skip to content

Commit 5993f96

Browse files
pdbrownbbatsov
authored andcommitted
[Inspector] Configure truncation limits
The limits after which the inspector truncates collection members are now configurable. Previously they were hardcoded to 5 and 150 for collection and atom (non-collection) members. Add keybindings to cider-inspector-mode: - a adjust atom truncation limit (default 150) - c adjust nested collection truncation limit (default 5) and add defcustoms to adjust the defaults - cider-inspector-max-atom-length - cider-inspector-max-coll-size
1 parent 3147a27 commit 5993f96

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### New features
66

77
* [#2930](https://github.com/clojure-emacs/cider/issues/2930): Add new customization variable `cider-test-default-include-selectors` and `cider-test-default-exclude-selectors` for specifying default test selectors when running commands such as `cider-test-run-ns-tests`.
8+
* [#3002](https://github.com/clojure-emacs/cider/pull/3002): [Inspector] Make collection member truncation limits configurable.
89

910
### Bugs fixed
1011

cider-inspector.el

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ The page size can be also changed interactively within the inspector."
5252
:group 'cider-inspector
5353
:package-version '(cider . "0.10.0"))
5454

55+
(defcustom cider-inspector-max-atom-length 150
56+
"Default max length of nested atoms before they are truncated.
57+
'Atom' here means any collection member that satisfies (complement coll?).
58+
The max length can be also changed interactively within the inspector."
59+
:type '(integer :tag "Max atom length" 150)
60+
:group 'cider-inspector
61+
:package-version '(cider . "1.1.0"))
62+
63+
(defcustom cider-inspector-max-coll-size 5
64+
"Default number of nested collection members to display before truncating.
65+
The max size can be also changed interactively within the inspector."
66+
:type '(integer :tag "Max collection size" 5)
67+
:group 'cider-inspector
68+
:package-version '(cider . "1.1.0"))
69+
5570
(defcustom cider-inspector-fill-frame nil
5671
"Controls whether the CIDER inspector window fills its frame."
5772
:type 'boolean
@@ -93,6 +108,8 @@ by clicking or navigating to them by other means."
93108
(define-key map (kbd "M-SPC") #'cider-inspector-prev-page)
94109
(define-key map (kbd "S-SPC") #'cider-inspector-prev-page)
95110
(define-key map "s" #'cider-inspector-set-page-size)
111+
(define-key map "a" #'cider-inspector-set-max-atom-length)
112+
(define-key map "c" #'cider-inspector-set-max-coll-size)
96113
(define-key map "d" #'cider-inspector-def-current-val)
97114
(define-key map [tab] #'cider-inspector-next-inspectable-object)
98115
(define-key map "\C-i" #'cider-inspector-next-inspectable-object)
@@ -112,6 +129,8 @@ by clicking or navigating to them by other means."
112129
["Next Page" cider-inspector-next-page]
113130
["Previous Page" cider-inspector-prev-page]
114131
["Set Page Size" cider-inspector-set-page-size]
132+
["Set Max Atom Length" cider-inspector-set-max-atom-length]
133+
["Set Max Collection Size" cider-inspector-set-max-coll-size]
115134
["Define Var" cider-inspector-def-current-val]
116135
"--"
117136
["Quit" cider-popup-buffer-quit-function]
@@ -187,7 +206,11 @@ current buffer's namespace."
187206
(interactive (list (cider-read-from-minibuffer "Inspect expression: " (cider-sexp-at-point))
188207
(cider-current-ns)))
189208
(setq cider-inspector--current-repl (cider-current-repl))
190-
(when-let* ((value (cider-sync-request:inspect-expr expr ns (or cider-inspector-page-size 32))))
209+
(when-let* ((value (cider-sync-request:inspect-expr
210+
expr ns
211+
cider-inspector-page-size
212+
cider-inspector-max-atom-length
213+
cider-inspector-max-coll-size)))
191214
(cider-inspector--render-value value)))
192215

193216
(defun cider-inspector-pop ()
@@ -235,8 +258,20 @@ Does nothing if already on the first page."
235258
"Set the page size in pagination mode to the specified PAGE-SIZE.
236259
237260
Current page will be reset to zero."
238-
(interactive "nPage size: ")
239-
(when-let* ((value (cider-sync-request:inspect-set-page-size page-size)))
261+
(interactive (list (read-number "Page size: " cider-inspector-page-size)))
262+
(when-let ((value (cider-sync-request:inspect-set-page-size page-size)))
263+
(cider-inspector--render-value value)))
264+
265+
(defun cider-inspector-set-max-atom-length (max-length)
266+
"Set the max length of nested atoms to MAX-LENGTH."
267+
(interactive (list (read-number "Max atom length: " cider-inspector-max-atom-length)))
268+
(when-let ((value (cider-sync-request:inspect-set-max-atom-length max-length)))
269+
(cider-inspector--render-value value)))
270+
271+
(defun cider-inspector-set-max-coll-size (max-size)
272+
"Set the number of nested collection members to display before truncating to MAX-SIZE."
273+
(interactive (list (read-number "Max collection size: " cider-inspector-max-coll-size)))
274+
(when-let ((value (cider-sync-request:inspect-set-max-coll-size max-size)))
240275
(cider-inspector--render-value value)))
241276

242277
(defun cider-inspector-def-current-val (var-name ns)
@@ -291,6 +326,20 @@ current-namespace."
291326
(cider-nrepl-send-sync-request cider-inspector--current-repl)
292327
(nrepl-dict-get "value")))
293328

329+
(defun cider-sync-request:inspect-set-max-atom-length (max-length)
330+
"Set the max length of nested atoms to MAX-LENGTH."
331+
(thread-first `("op" "inspect-set-max-atom-length"
332+
"max-atom-length" ,max-length)
333+
(cider-nrepl-send-sync-request cider-inspector--current-repl)
334+
(nrepl-dict-get "value")))
335+
336+
(defun cider-sync-request:inspect-set-max-coll-size (max-size)
337+
"Set the number of nested collection members to display before truncating to MAX-SIZE."
338+
(thread-first `("op" "inspect-set-max-coll-size"
339+
"max-coll-size" ,max-size)
340+
(cider-nrepl-send-sync-request cider-inspector--current-repl)
341+
(nrepl-dict-get "value")))
342+
294343
(defun cider-sync-request:inspect-def-current-val (ns var-name)
295344
"Defines a var with VAR-NAME in NS with the current inspector value."
296345
(thread-first `("op" "inspect-def-current-value"
@@ -299,12 +348,19 @@ current-namespace."
299348
(cider-nrepl-send-sync-request cider-inspector--current-repl)
300349
(nrepl-dict-get "value")))
301350

302-
(defun cider-sync-request:inspect-expr (expr ns page-size)
351+
(defun cider-sync-request:inspect-expr (expr ns page-size max-atom-length max-coll-size)
303352
"Evaluate EXPR in context of NS and inspect its result.
304-
Set the page size in paginated view to PAGE-SIZE."
353+
Set the page size in paginated view to PAGE-SIZE, maximum length of atomic
354+
collection members to MAX-ATOM-LENGTH, and maximum size of nested collections to
355+
MAX-COLL-SIZE if non nil."
305356
(thread-first (append (nrepl--eval-request expr ns)
306357
`("inspect" "true"
307-
"page-size" ,page-size))
358+
,@(when page-size
359+
`("page-size" ,page-size))
360+
,@(when max-atom-length
361+
`("max-atom-length" ,max-atom-length))
362+
,@(when max-coll-size
363+
`("max-coll-size" ,max-coll-size))))
308364
(cider-nrepl-send-sync-request cider-inspector--current-repl)
309365
(nrepl-dict-get "value")))
310366

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ You'll have access to additional keybindings in the inspector buffer
4949
| kbd:[s]
5050
| Set a new page size in paginated view
5151

52+
| kbd:[c]
53+
| Set a new maximum size above which nested collections are truncated
54+
55+
| kbd:[a]
56+
| Set a new maximum length above which nested atoms (non-collections) are truncated
57+
5258
| kbd:[d]
5359
| Defines a var in the REPL namespace with current inspector value
5460
|===
@@ -63,6 +69,14 @@ The inspector buffer is automatically selected by default. You
6369
can disable the auto selection with the variable
6470
`cider-inspector-auto-select-buffer`.
6571

72+
You can set the amount of data shown by default with the variables
73+
`cider-inspector-page-size`, `cider-inspector-max-coll-size`, and
74+
`cider-inspector-max-atom-length`. The values can be adjusted for the current
75+
inspector buffer using the `s`, `c`, and `a` keybindings.
76+
77+
If you enable `cider-inspector-fill-frame`, the inspector window fills its
78+
frame.
79+
6680
== Additional Resources
6781

6882
* https://practicalli.github.io/spacemacs/evaluating-clojure/inspect.html[Using CIDER's Inspector in Spacemacs]

0 commit comments

Comments
 (0)