How to Reload files upon save when using swank+leiningen+emacs
Asked Answered
H

3

22

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.

Hettie answered 7/4, 2010 at 21:58 Comment(0)
S
16

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).

Saari answered 8/4, 2010 at 0:48 Comment(0)
W
13

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)
Warthman answered 8/4, 2010 at 12:15 Comment(0)
G
8

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)
Gemsbok answered 8/4, 2010 at 3:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.