views:

235

answers:

3

I'm looking to set up slime+lein-swank to reload source files referenced from the repl when i save the file. currently i do this:

  • edit file
  • save file
  • switch to repl
  • (use :reload-all 'com.package.namespace)
  • test stuff

I want to not have to remember to do step 4.

+7  A: 

You can use SLIME's C-c C-k before switching to the REPL, for slime-compile-and-load-file. It will prompt you to save the file if you haven't already. When it's done, the things which you've redefined should be available at the SLIME REPL in their new versions. Then you could use C-c C-z to bring up the REPL (close it with C-x 0 when you don't need it anymore).

Michał Marczyk
+4  A: 

Like the previous answer I use those same keystrokes but record them into a macro and bind it to a key. That way it's just one keypress to save, compile and switch to the REPL. It ends up looking something like this:

(fset 'compile-and-goto-repl
   "\C-x\C-s\C-c\C-k\C-c\C-z")

(global-set-key [f6] 'compile-and-goto-repl)
Glen
+2  A: 

Setup a hook in .emacs:

(defun clojure-slime-maybe-compile-and-load-file ()
  "Call function `slime-compile-and-load-file' if current buffer is connected to a swank server.                                                               

Meant to be used in `after-save-hook'."
  (when (and (eq major-mode 'clojure-mode) (slime-connected-p))
    (slime-compile-and-load-file)))


(add-hook 'after-save-hook 'clojure-slime-maybe-compile-and-load-file)
Jürgen Hötzel