Skip to content

Commit 90561f1

Browse files
authored
Add evaluate and tap commands for last-sexp and sexp-at-point (#3240)
1 parent f54101f commit 90561f1

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [#2946](https://github.com/clojure-emacs/cider/issues/2946): Add custom var `cider-merge-sessions` to allow combining sessions in two different ways: Setting `cider-merge-sessions` to `'host` will merge all sessions associated with the same host within a project. Setting it to `'project` will combine all sessions of a project irrespective of their host.
99
- Support Gradle jack-in via the Gradle wrapper (`gradlew`), instead of just a globally installed `gradle` on the `PATH`.
1010
- Gradle projects can now inject dependencies and middleware as with other build tools (dependency injection requires [Clojurephant](https://github.com/clojurephant/clojurephant) 0.7.0 or higher).
11+
- [#3239](https://github.com/clojure-emacs/cider/issues/3239): Added commands to evaluate and tap last sexp and sexp at point.
1112

1213
## Changes
1314

cider-eval.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,25 @@ If invoked with OUTPUT-TO-CURRENT-BUFFER, output the result to current buffer."
10161016
(goto-char (cadr (cider-sexp-at-point 'bounds)))
10171017
(cider-eval-last-sexp output-to-current-buffer)))
10181018

1019+
(defun cider-tap-last-sexp (&optional output-to-current-buffer)
1020+
"Evaluate and tap the expression preceding point.
1021+
If invoked with OUTPUT-TO-CURRENT-BUFFER, print the result in the current
1022+
buffer."
1023+
(interactive "P")
1024+
(let ((tapped-form (concat "(clojure.core/doto " (cider-last-sexp) " (clojure.core/tap>))")))
1025+
(cider-interactive-eval tapped-form
1026+
(when output-to-current-buffer (cider-eval-print-handler))
1027+
nil
1028+
(cider--nrepl-pr-request-map))))
1029+
1030+
(defun cider-tap-sexp-at-point (&optional output-to-current-buffer)
1031+
"Evaluate and tap the expression around point.
1032+
If invoked with OUTPUT-TO-CURRENT-BUFFER, output the result to current buffer."
1033+
(interactive "P")
1034+
(save-excursion
1035+
(goto-char (cadr (cider-sexp-at-point 'bounds)))
1036+
(cider-tap-last-sexp output-to-current-buffer)))
1037+
10191038
(defvar-local cider-previous-eval-context nil
10201039
"The previous evaluation context if any.
10211040
That's set by commands like `cider-eval-last-sexp-in-context'.")
@@ -1422,8 +1441,10 @@ passing arguments."
14221441
(define-key map (kbd "n") #'cider-eval-ns-form)
14231442
(define-key map (kbd "d") #'cider-eval-defun-at-point)
14241443
(define-key map (kbd "e") #'cider-eval-last-sexp)
1444+
(define-key map (kbd "q") #'cider-tap-last-sexp)
14251445
(define-key map (kbd "l") #'cider-eval-list-at-point)
14261446
(define-key map (kbd "v") #'cider-eval-sexp-at-point)
1447+
(define-key map (kbd "t") #'cider-tap-sexp-at-point)
14271448
(define-key map (kbd "o") #'cider-eval-sexp-up-to-point)
14281449
(define-key map (kbd ".") #'cider-read-and-eval-defun-at-point)
14291450
(define-key map (kbd "z") #'cider-eval-defun-up-to-point)
@@ -1438,8 +1459,10 @@ passing arguments."
14381459
(define-key map (kbd "C-n") #'cider-eval-ns-form)
14391460
(define-key map (kbd "C-d") #'cider-eval-defun-at-point)
14401461
(define-key map (kbd "C-e") #'cider-eval-last-sexp)
1462+
(define-key map (kbd "C-q") #'cider-tap-last-sexp)
14411463
(define-key map (kbd "C-l") #'cider-eval-list-at-point)
14421464
(define-key map (kbd "C-v") #'cider-eval-sexp-at-point)
1465+
(define-key map (kbd "C-t") #'cider-tap-sexp-at-point)
14431466
(define-key map (kbd "C-o") #'cider-eval-sexp-up-to-point)
14441467
(define-key map (kbd "C-.") #'cider-read-and-eval-defun-at-point)
14451468
(define-key map (kbd "C-z") #'cider-eval-defun-up-to-point)

cider-mode.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ If invoked with a prefix ARG eval the expression after inserting it."
320320
"--"
321321
["Eval current list" cider-eval-list-at-point]
322322
["Eval current sexp" cider-eval-sexp-at-point]
323+
["Eval and tap current sexp" cider-tap-sexp-at-point]
323324
["Eval current sexp to point" cider-eval-sexp-up-to-point]
324325
["Eval current sexp in context" cider-eval-sexp-at-point-in-context]
325326
"--"
326327
["Eval last sexp" cider-eval-last-sexp]
328+
["Eval and tap last sexp" cider-tap-last-sexp]
327329
["Eval last sexp in context" cider-eval-last-sexp-in-context]
328330
["Eval last sexp and insert" cider-eval-print-last-sexp
329331
:keys "\\[universal-argument] \\[cider-eval-last-sexp]"]

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ Below is a listing of most keybindings for evaluation commands:
382382
kbd:[C-c C-e]
383383
| Evaluate the form preceding point and display the result in the echo area and/or in an buffer overlay (according to `cider-use-overlays`). If invoked with a prefix argument, insert the result into the current buffer.
384384

385+
| `cider-tap-last-sexp`
386+
| kbd:[C-c C-v q] +
387+
kbd:[C-c C-v C-q]
388+
| Like `cider-eval-last-sexp` but also taps the result.
389+
385390
| `cider-eval-last-sexp-and-replace`
386391
| kbd:[C-c C-v w]
387392
| Evaluate the form preceding point and replace it with its result.
@@ -423,6 +428,11 @@ kbd:[C-c C-v C-v]
423428
kbd:[C-u C-c C-c]
424429
| Debug the top level form under point and walk through its evaluation
425430

431+
| `cider-tap-sexp-at-point`
432+
| kbd:[C-c C-v t] +
433+
kbd:[C-c C-v C-t]
434+
| Evaluate and tap the form around point.
435+
426436
| `cider-eval-defun-up-to-point`
427437
| kbd:[C-c C-v z]
428438
| Evaluate the preceding top-level form up to the point.

0 commit comments

Comments
 (0)