diff --git a/CHANGELOG.md b/CHANGELOG.md index 252d603eb..32611ce66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ used in a project, particular if it is lower than minimum required for CIDER. * Allow the ns displayed by eldoc to be tailored via `cider-eldoc-ns-function`. * After connecting a ClojureScript REPL, CIDER will try to figure out if it's being served on a port and will offer to open it in a browser. +* [#1720](https://github.com/clojure-emacs/cider/issues/1720): Add a command `cider-eval-current-sexp` to evaluate the form around point (bound to `C-c C-v`). ### Changes diff --git a/cider-interaction.el b/cider-interaction.el index 13388a200..c9b416228 100644 --- a/cider-interaction.el +++ b/cider-interaction.el @@ -1087,6 +1087,14 @@ If invoked with a PREFIX argument, print the result in the current buffer." (backward-kill-sexp) (cider-interactive-eval last-sexp (cider-eval-print-handler)))) +(defun cider-eval-current-sexp (&optional prefix) + "Evaluate the expression around point. +If invoked with a PREFIX argument, print the result in the current buffer." + (interactive "P") + (save-excursion + (up-list) + (cider-eval-last-sexp prefix))) + (defun cider-eval-defun-to-comment (loc) "Evaluate the \"top-level\" form and insert result as comment at LOC. diff --git a/cider-mode.el b/cider-mode.el index 0d1205df3..d02c886a2 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -213,6 +213,7 @@ Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."] (defconst cider-mode-eval-menu '("CIDER Eval" :visible cider-connections ["Eval top-level sexp" cider-eval-defun-at-point] + ["Eval current sexp" cider-eval-current-sexp] ["Eval last sexp" cider-eval-last-sexp] ["Eval selected region" cider-eval-region] ["Eval ns form" cider-eval-ns-form] @@ -287,6 +288,7 @@ Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."] (define-key map (kbd "C-x C-e") #'cider-eval-last-sexp) (define-key map (kbd "C-c C-e") #'cider-eval-last-sexp) (define-key map (kbd "C-c C-w") #'cider-eval-last-sexp-and-replace) + (define-key map (kbd "C-c C-v") #'cider-eval-current-sexp) (define-key map (kbd "C-c M-;") #'cider-eval-defun-to-comment) (define-key map (kbd "C-c M-e") #'cider-eval-last-sexp-to-repl) (define-key map (kbd "C-c M-p") #'cider-insert-last-sexp-in-repl) diff --git a/doc/interactive_programming.md b/doc/interactive_programming.md index 862dafc46..1591601c7 100644 --- a/doc/interactive_programming.md +++ b/doc/interactive_programming.md @@ -25,6 +25,7 @@ Here's a list of `cider-mode`'s keybindings: C-c C-p | Evaluate the form preceding point and pretty-print the result in a popup buffer. C-c C-f | Evaluate the top level form under point and pretty-print the result in a popup buffer. C-M-x
C-c C-c | Evaluate the top level form under point and display the result in the echo area. +C-c C-v | Evaluate the form around point. C-u C-M-x
C-u C-c C-c | Debug the top level form under point and walk through its evaluation C-c C-r | Evaluate the region and display the result in the echo area. C-c C-b | Interrupt any pending evaluations.