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

亡梦爱人 提交于 2019-11-27 13:38:12

问题


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.


回答1:


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




回答2:


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)



回答3:


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)


来源:https://stackoverflow.com/questions/2596222/how-to-reload-files-upon-save-when-using-swankleiningenemacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!