Skip to content

Instantly share code, notes, and snippets.

@Quezion
Last active February 12, 2022 01:19
Show Gist options
  • Save Quezion/4e18ec42126c8810b7ef23d40a934ec7 to your computer and use it in GitHub Desktop.
Save Quezion/4e18ec42126c8810b7ef23d40a934ec7 to your computer and use it in GitHub Desktop.
Make cider-eval-last-sexp C-x C-e output to REPL buffer
;; Makes Emacs do Cursive's default behavior of inserting & evaling at REPL on C-x C-e
;; Tested on Feb 11 2021 with Emacs 27.2, CIDER 20220125.1326
;; see discussion https://github.com/clojure-emacs/cider/issues/2617
;; taken from WIP commit https://github.com/suvratapte/cider/commit/c177120ff243e032ee6e120e46ac4cccefc07991#diff-3f8317548fccd07e43ee8e69be1b3171
(defun cider-insert-and-eval-last-sexp-in-repl (&rest args)
"Insert the expression preceding point in the REPL buffer and eval."
(interactive)
(cider-insert-last-sexp-in-repl t)
(cider-switch-to-last-clojure-buffer))
(define-key cider-mode-map (kbd "C-x C-e") #'cider-insert-and-eval-last-sexp-in-repl)
@jvtrigueros
Copy link

jvtrigueros commented Feb 12, 2022

The only improvement I would make is to add this a call to (cider-switch-to-last-clojure-buffer) for 1:1 behaviour like so:

(defun cider-insert-and-eval-last-sexp-in-repl (&rest args)
  "Insert the expression preceding point in the REPL buffer and eval."
  (interactive)
  (cider-insert-in-repl (cider-last-sexp) t)
  (cider-switch-to-last-clojure-buffer))

@Quezion
Copy link
Author

Quezion commented Feb 12, 2022

👍 Good suggestion, updated gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment