Skip to content

Commit e9d2d87

Browse files
committed
[Fix #1748] Add new command cider-pprint-eval-last-sexp-to-repl
The command evals the preceding sexp and inserts its pretty-printed output in the REPL.
1 parent 5d2df05 commit e9d2d87

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ request dispatch.
1111
* Add a new interactive command `nrepl-toggle-message-logging`. It allows you to quickly toggle nREPL message logging on and off
1212
within the scope of your current Emacs session.
1313
* [#1851](https://github.com/clojure-emacs/cider/issues/1851): Add a command to rerun the last test ran via `cider-test-run-test`. The new command is named `cider-test-rerun-test` and is about to `C-c C-t (C-)g`.
14+
* [#1748](https://github.com/clojure-emacs/cider/issues/1748): Add new interactive command `cider-pprint-eval-last-sexp-to-repl`.
1415

1516
### Changes
1617

cider-interaction.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,20 @@ If invoked with a PREFIX argument, switch to the REPL buffer."
11361136
(when prefix
11371137
(cider-switch-to-repl-buffer)))
11381138

1139+
(defun cider-pprint-eval-last-sexp-to-repl (&optional prefix)
1140+
"Evaluate the expression preceding point and insert its pretty-printed result in the REPL.
1141+
If invoked with a PREFIX argument, switch to the REPL buffer."
1142+
(interactive "P")
1143+
(let* ((conn-buffer (cider-current-connection))
1144+
(right-margin (max fill-column
1145+
(1- (window-width (get-buffer-window conn-buffer))))))
1146+
(cider-interactive-eval nil
1147+
(cider-insert-eval-handler conn-buffer)
1148+
(cider-last-sexp 'bounds)
1149+
(cider--nrepl-pprint-request-plist (or right-margin fill-column))))
1150+
(when prefix
1151+
(cider-switch-to-repl-buffer)))
1152+
11391153
(defun cider-eval-print-last-sexp ()
11401154
"Evaluate the expression preceding point.
11411155
Print its value into the current buffer."

cider-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."]
226226
["Eval last sexp in popup buffer" cider-pprint-eval-last-sexp]
227227
["Eval last sexp and replace" cider-eval-last-sexp-and-replace]
228228
["Eval last sexp to REPL" cider-eval-last-sexp-to-repl]
229+
["Eval last sexp and pretty-print to REPL" cider-pprint-eval-last-sexp-to-repl]
229230
["Insert last sexp in REPL" cider-insert-last-sexp-in-repl]
230231
["Eval top-level sexp to comment" cider-eval-defun-to-comment]
231232
"--"

0 commit comments

Comments
 (0)