Skip to content

Instantly share code, notes, and snippets.

@jgrodziski
Created September 3, 2013 14:08
Show Gist options
  • Save jgrodziski/6424436 to your computer and use it in GitHub Desktop.
Save jgrodziski/6424436 to your computer and use it in GitHub Desktop.
(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