Skip to content

Commit

Permalink
Inspector: introduce cider-inspector-tap-current-val command
Browse files Browse the repository at this point in the history
Fixes #3548
  • Loading branch information
behrica authored and vemv committed Oct 24, 2023
1 parent 1203129 commit 966cae4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### New features

- [#3529](https://github.com/clojure-emacs/cider/issues/3529): CIDER inspector: introduce `cider-inspector-previous-sibling`, `cider-inspector-next-sibling` commands ([doc](https://docs.cider.mx/cider/debugging/inspector.html#usage)).
- [#3548](https://github.com/clojure-emacs/cider/issues/3548): CIDER inspector: introduce `cider-inspector-tap-current-val` command ([doc](https://docs.cider.mx/cider/debugging/inspector.html#usage)).

### Changes

Expand Down
18 changes: 18 additions & 0 deletions cider-inspector.el
Expand Up @@ -106,6 +106,7 @@ by clicking or navigating to them by other means."
(define-key map "a" #'cider-inspector-set-max-atom-length)
(define-key map "c" #'cider-inspector-set-max-coll-size)
(define-key map "d" #'cider-inspector-def-current-val)
(define-key map "t" #'cider-inspector-tap-current-val)
(define-key map [tab] #'cider-inspector-next-inspectable-object)
(define-key map "\C-i" #'cider-inspector-next-inspectable-object)
(define-key map "n" #'cider-inspector-next-inspectable-object)
Expand Down Expand Up @@ -328,6 +329,19 @@ current-namespace."
(cider-inspector--render-value value)
(message "%s#'%s/%s = %s" cider-eval-result-prefix ns var-name value)))

(defun cider-inspector-tap-current-val ()
"Sends the current Inspector current value to `tap>'."
(interactive)
;; NOTE: we don't set `cider-inspector--current-repl', because we mean to tap the current value of an existing Inspector,
;; so whatever repl was used for it, should be used here.
(if cider-inspector--current-repl
(let ((response (cider-sync-request:inspect-tap-current-val)))
(nrepl-dbind-response response (value err)
(if value
(message "Successully tapped the current Inspector value")
(error"Could not tap the current Inspector value: %s" err))))
(user-error "No CIDER session found")))

;; nREPL interactions
(defun cider-sync-request:inspect-pop ()
"Move one level up in the inspector stack."
Expand Down Expand Up @@ -402,6 +416,10 @@ MAX-SIZE is the new value."
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-tap-current-val ()
"Sends current inspector value to tap>."
(cider-nrepl-send-sync-request '("op" "inspect-tap-current-value") cider-inspector--current-repl))

(defun cider-sync-request:inspect-expr (expr ns page-size max-atom-length max-coll-size)
"Evaluate EXPR in context of NS and inspect its result.
Set the page size in paginated view to PAGE-SIZE, maximum length of atomic
Expand Down
9 changes: 9 additions & 0 deletions doc/modules/ROOT/pages/debugging/inspector.adoc
Expand Up @@ -22,6 +22,10 @@ the last result. This behavior can be controlled with the variable
TIP: The inspector can also be invoked in the middle of a debugging
session, see xref:debugging/debugger.adoc[here] for more details.

TIP: The current value of the debugger can be as sent as well to Clojure's
`tap>` facility. This can be used to integrate CIDER with various external
tools which render tapped values in a web browser, for example.

You'll have access to additional keybindings in the inspector buffer
(which is internally using `cider-inspector-mode`):

Expand Down Expand Up @@ -79,6 +83,11 @@ You'll have access to additional keybindings in the inspector buffer
| kbd:[0]
| `cider-inspector-next-sibling`
| Navigates to the next sibling, within a sequential collection.

| kbd:[t]
| `cider-inspector-tap-current-val`
| Performs `tap>` using the inspector's current value as it argument.

|===

== Configuration
Expand Down

0 comments on commit 966cae4

Please sign in to comment.