开发者

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

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:

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


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


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)


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜