summaryrefslogtreecommitdiff
path: root/cider-ns.el
diff options
context:
space:
mode:
authorAndrea Richiardi <a.richiardi.work@gmail.com>2018-08-01 09:43:35 -0700
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2018-08-02 22:14:34 +0300
commit623a669619a35c3f02dd1172665aa9db9fc1e761 (patch)
tree514dfed1529490a9631a8cfd35f09e8b4692bd93 /cider-ns.el
parenta1f86b38c4a07c254d444cf0280d2fe29eb6a830 (diff)
Add cider-ns-reload and cider-ns-reload-all commands
The C-c M-n l has been assigned to cider-ns-reload while C-c M-n M-l has been assigned to cider-ns-reload-all.
Diffstat (limited to 'cider-ns.el')
-rw-r--r--cider-ns.el65
1 files changed, 63 insertions, 2 deletions
diff --git a/cider-ns.el b/cider-ns.el
index 3ba96c32..9a3f5aca 100644
--- a/cider-ns.el
+++ b/cider-ns.el
@@ -22,8 +22,38 @@
;;; Commentary:
-;; Smart code refresh functionality based on ideas
-;; fromhttp://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded
+;; Smart code refresh functionality based on ideas from:
+;; http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded
+;;
+;; Note that refresh with clojure.tools.namespace.repl is a smarter way to
+;; reload code: the traditional way to reload Clojure code without restarting
+;; the JVM is (require ... :reload) or an editor/IDE feature that does the same
+;; thing.
+;;
+;; This has several problems:
+;;
+;; If you modify two namespaces which depend on each other, you must remember to
+;; reload them in the correct order to avoid compilation errors.
+;;
+;; If you remove definitions from a source file and then reload it, those
+;; definitions are still available in memory. If other code depends on those
+;; definitions, it will continue to work but will break the next time you
+;; restart the JVM.
+;;
+;; If the reloaded namespace contains defmulti, you must also reload all of the
+;; associated defmethod expressions.
+;;
+;; If the reloaded namespace contains defprotocol, you must also reload any
+;; records or types implementing that protocol and replace any existing
+;; instances of those records/types with new instances.
+;;
+;; If the reloaded namespace contains macros, you must also reload any
+;; namespaces which use those macros.
+;;
+;; If the running program contains functions which close over values in the
+;; reloaded namespace, those closed-over values are not updated (This is common
+;; in web applications which construct the "handler stack" as a composition of
+;; functions.)
;;; Code:
@@ -146,6 +176,37 @@ Its behavior is controlled by `cider-save-files-on-cider-ns-refresh'."
(eq system-type 'windows-nt))))))))
;;;###autoload
+(defun cider-ns-reload (&optional prompt)
+ "Send a (require 'ns :reload) to the REPL.
+
+With an argument PROMPT, it prompts for a namespace name. This is the
+Clojure out of the box reloading experience and does not rely on
+org.clojure/tools.namespace. See Commentary of this file for a longer list
+of differences. From the Clojure doc: \":reload forces loading of all the
+identified libs even if they are already loaded\"."
+ (interactive "P")
+ (let ((ns (if prompt
+ (string-remove-prefix "'" (read-from-minibuffer "Namespace: " (clojure-find-ns)))
+ (clojure-find-ns))))
+ (cider-interactive-eval (format "(require '%s :reload)" ns))))
+
+;;;###autoload
+(defun cider-ns-reload-all (&optional prompt)
+ "Send a (require 'ns :reload-all) to the REPL.
+
+With an argument PROMPT, it prompts for a namespace name. This is the
+Clojure out of the box reloading experience and does not rely on
+org.clojure/tools.namespace. See Commentary of this file for a longer list
+of differences. From the Clojure doc: \":reload-all implies :reload and
+also forces loading of all libs that the identified libs directly or
+indirectly load via require\"."
+ (interactive "P")
+ (let ((ns (if prompt
+ (string-remove-prefix "'" (read-from-minibuffer "Namespace: " (clojure-find-ns)))
+ (clojure-find-ns))))
+ (cider-interactive-eval (format "(require '%s :reload-all)" ns))))
+
+;;;###autoload
(defun cider-ns-refresh (&optional mode)
"Reload modified and unloaded namespaces on the classpath.