Skip to content

Commit 33baff8

Browse files
samhedinvemv
authored andcommitted
Introduce cider-eval-dwim
Closes #3496
1 parent ee1975d commit 33baff8

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

CHANGELOG.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55
### New features
66

7+
- [#3364](https://github.com/clojure-emacs/cider/pull/3364): Update enrich-classpath, adding Clojure CLI compatibility, and reworking its integration into CIDER.
8+
* It will be progressively refined and [documented](https://docs.cider.mx/cider/config/basic_config.html#use-enrich-classpath), please consider this alpha software.
9+
- [#3472](https://github.com/clojure-emacs/cider/pull/3472): render Java doc comments and arglists with an improved format, and improve Java interop type inference.
10+
* Requires enrich-classpath to be enabled (see previous bullet point).
711
- [#3352](https://github.com/clojure-emacs/cider/pull/3352) Add CIDER Log Mode, a major mode that allows you to capture, debug, inspect and view log events emitted by Java logging frameworks.
8-
- `cider-test`: add timing information.
9-
- `cider-test`: fail-fast by default, as controlled by the new `cider-test-fail-fast` defcustom and `cider-test-toggle-fail-fast` keybinding.
10-
- Infer indentation specs when possible ([doc](https://docs.cider.mx/cider/indent_spec.html#indentation-inference)).
1112
- [#3418](https://github.com/clojure-emacs/cider/issues/3418): Introduce `cider-clojure-compilation-error-phases`.
1213
- This prevents stacktraces from showing up whenever the [:clojure.error/phase](https://clojure.org/reference/repl_and_main#_at_repl) indicates that it's a compilation error.
13-
- Add new customization variable `cider-clojurec-eval-destination` to allow specifying which REPL CLJC evals are sent to.
14-
- [#3354](https://github.com/clojure-emacs/cider/issues/3354): Add new customization variable `cider-reuse-dead-repls` to control how dead REPL buffers are reused on new connections.
15-
- [#3364](https://github.com/clojure-emacs/cider/pull/3364): Update enrich-classpath, adding Clojure CLI compatibility, and reworking its integration into CIDER.
16-
* It will be progressively refined and documented, please consider this alpha software.
14+
- Infer indentation specs when possible ([doc](https://docs.cider.mx/cider/indent_spec.html#indentation-inference)).
1715
- [#2958](https://github.com/clojure-emacs/cider/issues/2958), [#3279](https://github.com/clojure-emacs/cider/issues/3279): `cider-test-run-test`: support arbitrary deftest-like forms, defns with :test metadata, and search for a `-test` counterpart for a given defn (following `cider-test-infer-test-ns` logic).
1816
- This also makes obsolete the `cider-test-defining-forms` customization variable.
17+
- `cider-test`: add timing information.
18+
- `cider-test`: fail-fast by default, as controlled by the new `cider-test-fail-fast` defcustom and `cider-test-toggle-fail-fast` keybinding.
19+
- [#3352](https://github.com/clojure-emacs/cider/pull/3496) Introduce [`cider-eval-dwim`](https://docs.cider.mx/cider/usage/cider_mode.html#key-reference).
20+
- Add new customization variable `cider-clojurec-eval-destination` to allow specifying which REPL CLJC evals are sent to.
21+
- [#3354](https://github.com/clojure-emacs/cider/issues/3354): Add new customization variable `cider-reuse-dead-repls` to control how dead REPL buffers are reused on new connections.
1922

2023
### Bugs fixed
2124

cider-eval.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,17 @@ buffer, else display in a popup buffer."
13611361
'help-echo "Breakpoint. Reevaluate this form to remove it."
13621362
:type 'cider-fragile))))
13631363

1364+
(defun cider-eval-dwim (&optional debug-it)
1365+
"If no region is active, call `cider-eval-defun-at-point' with DEBUG-IT.
1366+
If a region is active, run `cider-eval-region'.
1367+
1368+
Always binds `clojure-toplevel-inside-comment-form' to t."
1369+
(interactive "P")
1370+
(let ((clojure-toplevel-inside-comment-form t))
1371+
(if (use-region-p)
1372+
(cider-eval-region (region-beginning) (region-end))
1373+
(cider-eval-defun-at-point debug-it))))
1374+
13641375
(defun cider-eval-defun-at-point (&optional debug-it)
13651376
"Evaluate the current toplevel form, and print result in the minibuffer.
13661377
With DEBUG-IT prefix argument, also debug the entire form as with the
@@ -1543,6 +1554,7 @@ passing arguments."
15431554
(define-key map (kbd "w") #'cider-eval-last-sexp-and-replace)
15441555
(define-key map (kbd "r") #'cider-eval-region)
15451556
(define-key map (kbd "n") #'cider-eval-ns-form)
1557+
(define-key map (kbd "s") #'cider-eval-dwim)
15461558
(define-key map (kbd "d") #'cider-eval-defun-at-point)
15471559
(define-key map (kbd "e") #'cider-eval-last-sexp)
15481560
(define-key map (kbd "q") #'cider-tap-last-sexp)
@@ -1561,6 +1573,7 @@ passing arguments."
15611573
(define-key map (kbd "C-w") #'cider-eval-last-sexp-and-replace)
15621574
(define-key map (kbd "C-r") #'cider-eval-region)
15631575
(define-key map (kbd "C-n") #'cider-eval-ns-form)
1576+
(define-key map (kbd "C-s") #'cider-eval-dwim)
15641577
(define-key map (kbd "C-d") #'cider-eval-defun-at-point)
15651578
(define-key map (kbd "C-e") #'cider-eval-last-sexp)
15661579
(define-key map (kbd "C-q") #'cider-tap-last-sexp)

cider-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ If invoked with a prefix ARG eval the expression after inserting it."
338338
["Eval last sexp and pretty-print to REPL" cider-pprint-eval-last-sexp-to-repl]
339339
["Eval last sexp and pretty-print to comment" cider-pprint-eval-last-sexp-to-comment]
340340
"--"
341+
["Eval selected region if active, otherwise top-level sexp" cider-eval-dwim]
341342
["Eval selected region" cider-eval-region]
342343
["Eval ns form" cider-eval-ns-form]
343344
"--"

cider-util.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ through a stack of help buffers. Variables `help-back-label' and
734734
"Press <\\[cider-apropos]> to look for a symbol by some search string."
735735
"Press <\\[cider-apropos-documentation]> to look for a symbol that has some string in its docstring."
736736
"Press <\\[cider-eval-defun-at-point]> to eval the top-level form at point."
737+
"Press <\\[cider-eval-dwim]> to eval to run cider-eval-region if a region is active, and cider-eval-defun-at-point otherwise."
737738
"Press <\\[cider-eval-defun-up-to-point]> to eval the top-level form up to the point."
738739
"Press <\\[cider-eval-sexp-up-to-point]> to eval the current form up to the point."
739740
"Press <\\[cider-eval-sexp-at-point]> to eval the current form around the point."

doc/modules/ROOT/pages/usage/cider_mode.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ kbd:[C-c C-e]
8686
kbd:[C-c C-c]
8787
| Evaluate the top level form under point and display the result in the echo area.
8888

89+
| `cider-eval-dwim`
90+
| kbd:[C-c C-v s] +
91+
kbd:[C-c C-v C-s]
92+
| If no region is active, eval the toplevel form with cider-eval-defun-at-point. If a region is active, run cider-eval-region
93+
8994
| `cider-eval-list-at-point`
9095
| kbd:[C-c C-v l] +
9196
kbd:[C-c C-v C-l]

0 commit comments

Comments
 (0)