Created
September 3, 2013 14:08
-
-
Save jgrodziski/6424436 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun nrepl-send-to-repl () | |
"Send the appropriate forms to the repl to be evaluated." | |
(interactive) | |
(save-excursion | |
(cond | |
;; Region selected - evaluate region | |
((not (equal mark-active nil)) | |
(copy-region-as-kill (mark) (point))) | |
;; At/before sexp - evaluate next sexp | |
((or (looking-at "\s(") | |
(save-excursion | |
(ignore-errors (forward-char 1)) | |
(looking-at "\s("))) | |
(forward-list 1) | |
(let ((end (point)) | |
(beg (save-excursion | |
(backward-list 1) | |
(point)))) | |
(copy-region-as-kill beg end))) | |
;; At/after sexp - evaluate last sexp | |
((or (looking-at "\s)") | |
(save-excursion | |
(backward-char 1) | |
(looking-at "\s)"))) | |
(if (looking-at "\s)") | |
(forward-char 1)) | |
(let ((end (point)) | |
(beg (save-excursion | |
(backward-list 1) | |
(point)))) | |
(copy-region-as-kill beg end))) | |
;; Default - evaluate enclosing top-level sexp | |
(t (progn | |
(while (ignore-errors (progn | |
(backward-up-list) | |
t))) | |
(forward-list 1) | |
(let ((end (point)) | |
(beg (save-excursion | |
(backward-list 1) | |
(point)))) | |
(copy-region-as-kill beg end))))) | |
(set-buffer "*nrepl*") | |
(unless (eq (current-buffer) (window-buffer)) | |
(pop-to-buffer (current-buffer) t)) | |
;;(goto-char (point-max)) | |
(yank) | |
(previous-buffer))) | |
(global-set-key (kbd "C-c C-l") 'nrepl-send-to-repl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment