|
22 | 22 |
|
23 | 23 | ;;; Commentary:
|
24 | 24 |
|
25 |
| -;; Smart code refresh functionality based on ideas |
26 |
| -;; fromhttp://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded |
| 25 | +;; Smart code refresh functionality based on ideas from: |
| 26 | +;; http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded |
| 27 | +;; |
| 28 | +;; Note that refresh with clojure.tools.namespace.repl is a smarter way to |
| 29 | +;; reload code: the traditional way to reload Clojure code without restarting |
| 30 | +;; the JVM is (require ... :reload) or an editor/IDE feature that does the same |
| 31 | +;; thing. |
| 32 | +;; |
| 33 | +;; This has several problems: |
| 34 | +;; |
| 35 | +;; If you modify two namespaces which depend on each other, you must remember to |
| 36 | +;; reload them in the correct order to avoid compilation errors. |
| 37 | +;; |
| 38 | +;; If you remove definitions from a source file and then reload it, those |
| 39 | +;; definitions are still available in memory. If other code depends on those |
| 40 | +;; definitions, it will continue to work but will break the next time you |
| 41 | +;; restart the JVM. |
| 42 | +;; |
| 43 | +;; If the reloaded namespace contains defmulti, you must also reload all of the |
| 44 | +;; associated defmethod expressions. |
| 45 | +;; |
| 46 | +;; If the reloaded namespace contains defprotocol, you must also reload any |
| 47 | +;; records or types implementing that protocol and replace any existing |
| 48 | +;; instances of those records/types with new instances. |
| 49 | +;; |
| 50 | +;; If the reloaded namespace contains macros, you must also reload any |
| 51 | +;; namespaces which use those macros. |
| 52 | +;; |
| 53 | +;; If the running program contains functions which close over values in the |
| 54 | +;; reloaded namespace, those closed-over values are not updated (This is common |
| 55 | +;; in web applications which construct the "handler stack" as a composition of |
| 56 | +;; functions.) |
27 | 57 |
|
28 | 58 | ;;; Code:
|
29 | 59 |
|
@@ -145,6 +175,37 @@ Its behavior is controlled by `cider-save-files-on-cider-ns-refresh'."
|
145 | 175 | (file-truename default-directory)
|
146 | 176 | (eq system-type 'windows-nt))))))))
|
147 | 177 |
|
| 178 | +;;;###autoload |
| 179 | +(defun cider-ns-reload (&optional prompt) |
| 180 | + "Send a (require 'ns :reload) to the REPL. |
| 181 | +
|
| 182 | +With an argument PROMPT, it prompts for a namespace name. This is the |
| 183 | +Clojure out of the box reloading experience and does not rely on |
| 184 | +org.clojure/tools.namespace. See Commentary of this file for a longer list |
| 185 | +of differences. From the Clojure doc: \":reload forces loading of all the |
| 186 | +identified libs even if they are already loaded\"." |
| 187 | + (interactive "P") |
| 188 | + (let ((ns (if prompt |
| 189 | + (string-remove-prefix "'" (read-from-minibuffer "Namespace: " (clojure-find-ns))) |
| 190 | + (clojure-find-ns)))) |
| 191 | + (cider-interactive-eval (format "(require '%s :reload)" ns)))) |
| 192 | + |
| 193 | +;;;###autoload |
| 194 | +(defun cider-ns-reload-all (&optional prompt) |
| 195 | + "Send a (require 'ns :reload-all) to the REPL. |
| 196 | +
|
| 197 | +With an argument PROMPT, it prompts for a namespace name. This is the |
| 198 | +Clojure out of the box reloading experience and does not rely on |
| 199 | +org.clojure/tools.namespace. See Commentary of this file for a longer list |
| 200 | +of differences. From the Clojure doc: \":reload-all implies :reload and |
| 201 | +also forces loading of all libs that the identified libs directly or |
| 202 | +indirectly load via require\"." |
| 203 | + (interactive "P") |
| 204 | + (let ((ns (if prompt |
| 205 | + (string-remove-prefix "'" (read-from-minibuffer "Namespace: " (clojure-find-ns))) |
| 206 | + (clojure-find-ns)))) |
| 207 | + (cider-interactive-eval (format "(require '%s :reload-all)" ns)))) |
| 208 | + |
148 | 209 | ;;;###autoload
|
149 | 210 | (defun cider-ns-refresh (&optional mode)
|
150 | 211 | "Reload modified and unloaded namespaces on the classpath.
|
|
0 commit comments