Skip to content

Commit

Permalink
Add cider-inspector-def-current-val to cider-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas authored and bbatsov committed Oct 16, 2019
1 parent 809c856 commit ee2d014
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bugs fixed
* [#2730](https://github.com/clojure-emacs/cider/pull/2730) Require repl utilities into current namespace not just user ns
* New cider inspector command `cider-inspector-def-current-val` lets you define a var with the current inspector value.

## 0.23.0 (2019-10-08)

Expand Down
20 changes: 20 additions & 0 deletions cider-inspector.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The page size can be also changed interactively within the inspector."
(define-key map (kbd "M-SPC") #'cider-inspector-prev-page)
(define-key map (kbd "S-SPC") #'cider-inspector-prev-page)
(define-key map "s" #'cider-inspector-set-page-size)
(define-key map "d" #'cider-inspector-def-current-val)
(define-key map [tab] #'cider-inspector-next-inspectable-object)
(define-key map "\C-i" #'cider-inspector-next-inspectable-object)
(define-key map [(shift tab)] #'cider-inspector-previous-inspectable-object)
Expand All @@ -90,6 +91,7 @@ The page size can be also changed interactively within the inspector."
["Next Page" cider-inspector-next-page]
["Previous Page" cider-inspector-prev-page]
["Set Page Size" cider-inspector-set-page-size]
["Define Var" cider-inspector-def-current-val]
"--"
["Quit" cider-popup-buffer-quit-function]
))
Expand Down Expand Up @@ -215,6 +217,16 @@ Current page will be reset to zero."
(when-let* ((value (cider-sync-request:inspect-set-page-size page-size)))
(cider-inspector--render-value value)))

(defun cider-inspector-def-current-val (var-name ns)
"Defines a var with VAR-NAME in current namespace.
Doesn't modify current page."
(interactive (list (cider-read-from-minibuffer "Var name: ")
(cider-current-ns)))
(setq cider-inspector--current-repl (cider-current-repl))
(when-let* ((value (cider-sync-request:inspect-def-current-val ns var-name)))
(cider-inspector--render-value value)))

;; nREPL interactions
(defun cider-sync-request:inspect-pop ()
"Move one level up in the inspector stack."
Expand Down Expand Up @@ -254,6 +266,14 @@ Current page will be reset to zero."
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-def-current-val (ns var-name)
"Defines a var with VAR-NAME in NS with the current inspector value."
(thread-first `("op" "inspect-def-current-value"
"ns" ,ns
"var-name" ,var-name)
(cider-nrepl-send-sync-request cider-inspector--current-repl)
(nrepl-dict-get "value")))

(defun cider-sync-request:inspect-expr (expr ns page-size)
"Evaluate EXPR in context of NS and inspect its result.
Set the page size in paginated view to PAGE-SIZE."
Expand Down
3 changes: 3 additions & 0 deletions doc/modules/ROOT/pages/debugging/misc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ internally using `cider-inspector-mode`):

| kbd:[s]
| Set a new page size in paginated view

| kbd:[d]
| Defines a var with current inspector value
|===

0 comments on commit ee2d014

Please sign in to comment.