Skip to content

Commit 6350c4c

Browse files
committed
Add command to print the current value of the inspector.
This PR adds the interactive `cider-inspector-print-current-value` command that prints the current value of the inspector to the `cider-inspector-value-buffer` with the usual pretty printing machinery.
1 parent ee48d40 commit 6350c4c

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

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

33
## master (unreleased)
44

5+
- Add the `cider-inspector-print-current-value` command to print the
6+
current value of the inspector.
7+
58
### New features
69

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

cider-inspector.el

+24
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
(require 'cl-lib)
3131
(require 'easymenu)
3232
(require 'seq)
33+
(require 'cider-client)
3334
(require 'cider-eval)
3435

3536
;; ===================================
3637
;; Inspector Key Map and Derived Mode
3738
;; ===================================
3839

3940
(defconst cider-inspector-buffer "*cider-inspect*")
41+
(defconst cider-inspector-value-buffer "*cider-inspect-value*")
4042

4143
;;; Customization
4244
(defgroup cider-inspector nil
@@ -140,6 +142,7 @@ Can be turned to nil once the user sees and acknowledges the feature."
140142
(define-key map "n" #'cider-inspector-next-inspectable-object)
141143
(define-key map [(shift tab)] #'cider-inspector-previous-inspectable-object)
142144
(define-key map "p" #'cider-inspector-previous-inspectable-object)
145+
(define-key map "P" #'cider-inspector-print-current-value)
143146
(define-key map ":" #'cider-inspect-expr-from-inspector)
144147
(define-key map "f" #'forward-char)
145148
(define-key map "b" #'backward-char)
@@ -389,6 +392,26 @@ current-namespace."
389392
(cider-inspector--render-value result)
390393
(message "Defined current inspector value as #'%s/%s" ns var-name)))
391394

395+
(defun cider-inspector-print-current-value ()
396+
"Print the current value of the inspector."
397+
(interactive)
398+
(cider-ensure-connected)
399+
(cider-ensure-op-supported "inspect-print-current-value")
400+
(cider-popup-buffer cider-inspector-value-buffer nil 'clojure-mode 'ancillary)
401+
(cider-nrepl-send-request
402+
`("op" "inspect-print-current-value"
403+
,@(cider--nrepl-print-request-plist fill-column))
404+
(lambda (response)
405+
(with-current-buffer (get-buffer-create cider-inspector-value-buffer)
406+
(let ((inhibit-read-only t))
407+
(nrepl-dbind-response response (status value)
408+
(cond ((member "done" status)
409+
(goto-char (point-min)))
410+
((member "value" response)
411+
(insert value)
412+
(newline)))))))
413+
(cider-current-repl)))
414+
392415
(defun cider-inspector-tap-current-val ()
393416
"Sends the current Inspector current value to `tap>'."
394417
(interactive)
@@ -413,6 +436,7 @@ current-namespace."
413436
(_ (error "No object at point")))))
414437

415438
;; nREPL interactions
439+
416440
(defun cider-sync-request:inspect-pop ()
417441
"Move one level up in the inspector stack."
418442
(cider-nrepl-send-sync-request `("op" "inspect-pop")

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

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ You'll have access to additional keybindings in the inspector buffer
8585
| `cider-inspector-def-current-val`
8686
| 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.
8787

88+
| kbd:[P]
89+
| `cider-inspector-print-current-value`
90+
| Print the current value of the inspector to the `cider-inspector-value-buffer`.
91+
8892
| kbd:[9]
8993
| `cider-inspector-previous-sibling`
9094
| Navigates to the previous sibling, within a sequential collection.

0 commit comments

Comments
 (0)