Skip to content

Commit

Permalink
[Fix #1748] Add new command cider-pprint-eval-last-sexp-to-repl
Browse files Browse the repository at this point in the history
The command evals the preceding sexp and inserts its pretty-printed
output in the REPL.
  • Loading branch information
bbatsov committed Oct 8, 2016
1 parent 5d2df05 commit e9d2d87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ request dispatch.
* Add a new interactive command `nrepl-toggle-message-logging`. It allows you to quickly toggle nREPL message logging on and off
within the scope of your current Emacs session.
* [#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`.
* [#1748](https://github.com/clojure-emacs/cider/issues/1748): Add new interactive command `cider-pprint-eval-last-sexp-to-repl`.

### Changes

Expand Down
14 changes: 14 additions & 0 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,20 @@ If invoked with a PREFIX argument, switch to the REPL buffer."
(when prefix
(cider-switch-to-repl-buffer)))

(defun cider-pprint-eval-last-sexp-to-repl (&optional prefix)
"Evaluate the expression preceding point and insert its pretty-printed result in the REPL.
If invoked with a PREFIX argument, switch to the REPL buffer."
(interactive "P")
(let* ((conn-buffer (cider-current-connection))
(right-margin (max fill-column
(1- (window-width (get-buffer-window conn-buffer))))))
(cider-interactive-eval nil
(cider-insert-eval-handler conn-buffer)
(cider-last-sexp 'bounds)
(cider--nrepl-pprint-request-plist (or right-margin fill-column))))
(when prefix
(cider-switch-to-repl-buffer)))

(defun cider-eval-print-last-sexp ()
"Evaluate the expression preceding point.
Print its value into the current buffer."
Expand Down
1 change: 1 addition & 0 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Configure `cider-cljs-lein-repl' to change the ClojureScript REPL to use."]
["Eval last sexp in popup buffer" cider-pprint-eval-last-sexp]
["Eval last sexp and replace" cider-eval-last-sexp-and-replace]
["Eval last sexp to REPL" cider-eval-last-sexp-to-repl]
["Eval last sexp and pretty-print to REPL" cider-pprint-eval-last-sexp-to-repl]
["Insert last sexp in REPL" cider-insert-last-sexp-in-repl]
["Eval top-level sexp to comment" cider-eval-defun-to-comment]
"--"
Expand Down

0 comments on commit e9d2d87

Please sign in to comment.