Skip to content
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

add new inspector function to tap current value #3549

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changes

- [#3546](https://github.com/clojure-emacs/cider/issues/3546): Inspector: render Java items using `java-mode` syntax coloring.
- [#3548](https://github.com/clojure-emacs/cider/issues/3548): Inspector: add function to tap> the current inspector value.

### Bugs fixed

Expand Down
22 changes: 22 additions & 0 deletions cider-inspector.el
Original file line number Diff line number Diff line change
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 @@ -307,6 +308,21 @@ 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 current value to tap>."
(interactive)
(setq cider-inspector--current-repl (cider-current-repl))

(let* ((value (cider-sync-request:inspect-tap-current-val))
(elements (car (read-from-string value)))
(path-present (equal "--- Path:" (nth (- (length elements) 4) elements )))
(path-str (if path-present
(car (last elements))
"TOP-LEVEL")))
(cider-inspector--render-value value)
(message "%s# tapped element '%s'" cider-eval-result-prefix path-str)))


;; nREPL interactions
(defun cider-sync-request:inspect-pop ()
"Move one level up in the inspector stack."
Expand Down Expand Up @@ -369,6 +385,12 @@ 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>."
(thread-first `("op" "inspect-tap-current-value")
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(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
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 @@ -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 send 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 @@ -60,6 +64,10 @@ You'll have access to additional keybindings in the inspector buffer

| kbd:[d]
| 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.

| kbd:[t]
behrica marked this conversation as resolved.
Show resolved Hide resolved
| Sends the current inspector value to Clojure's tap>.

|===

== Configuration
Expand Down
Loading