diff --git a/CHANGELOG.md b/CHANGELOG.md index 439d1987c..4b63b32e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cider-inspector.el b/cider-inspector.el index 24f4a1eba..6f4bff447 100644 --- a/cider-inspector.el +++ b/cider-inspector.el @@ -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) @@ -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] )) @@ -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." @@ -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." diff --git a/doc/modules/ROOT/pages/debugging/misc.adoc b/doc/modules/ROOT/pages/debugging/misc.adoc index 12fcca04c..e97761e49 100644 --- a/doc/modules/ROOT/pages/debugging/misc.adoc +++ b/doc/modules/ROOT/pages/debugging/misc.adoc @@ -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 |===