Refactoring tool to move a Clojure namespace from one name/file to another, and update all references to that namespace in your other Clojure source files.
WARNING: This code is ALPHA and subject to change. It also modifies and deletes your source files! Make sure you have a backup or version control.
DISCLAIMER This is a heavily modified version of Stuart Sierra's original clojure.tools.namespace.move
Refactoring tool to move a Clojure namespace from one name/file to another, and update all references to that namespace in your other Clojure source files. WARNING: This code is ALPHA and subject to change. It also modifies and deletes your source files! Make sure you have a backup or version control. DISCLAIMER This is a heavily modified version of Stuart Sierra's original clojure.tools.namespace.move
(move-ns old-sym new-sym source-path extension dirs watermark)ALPHA: subject to change. Moves the source file (of the given extension,
relative to source-path) for namespace old-sym to new-sym, then replaces
all references to the old name with the new name across every Clojure source
file under dirs. The single-rename combination of move-ns-files! and
replace-ns-symbol-in-source-files.
WARNING: This function modifies and deletes your source files! Make sure you have a backup or version control.
ALPHA: subject to change. Moves the source file (of the given `extension`, relative to `source-path`) for namespace `old-sym` to `new-sym`, then replaces all references to the old name with the new name across every Clojure source file under `dirs`. The single-rename combination of `move-ns-files!` and `replace-ns-symbol-in-source-files`. WARNING: This function modifies and deletes your source files! Make sure you have a backup or version control.
(move-ns-file old-sym new-sym extension source-path)ALPHA: subject to change. Moves the .clj or .cljc source file (found relative to source-path) for the namespace named old-sym to a file for a namespace named new-sym.
WARNING: This function moves and deletes your source files! Make sure you have a backup or version control.
ALPHA: subject to change. Moves the .clj or .cljc source file (found relative to source-path) for the namespace named old-sym to a file for a namespace named new-sym. WARNING: This function moves and deletes your source files! Make sure you have a backup or version control.
(move-ns-files! old-sym new-sym source-path extension)Moves the source file(s) for old-sym to new-sym WITHOUT rewriting any
references (also moves a .cljc companion when moving a .clj/.cljs).
WARNING: moves and deletes source files.
Moves the source file(s) for `old-sym` to `new-sym` WITHOUT rewriting any references (also moves a `.cljc` companion when moving a `.clj`/`.cljs`). WARNING: moves and deletes source files.
(replace-ns-symbol content
old-sym
new-sym
watermark
extension-of-moved
file-ext)ALPHA: subject to change. Given Clojure source as a file, replaces all occurrences of the namespace name old-sym with new-sym and returns modified source as a string.
Splits the source file, parses the ns macro if found to do all the necessary transformations. Works on the body of namespace as text as simpler transformations are needed. When done puts the ns form and body back together.
ALPHA: subject to change. Given Clojure source as a file, replaces all occurrences of the namespace name old-sym with new-sym and returns modified source as a string. Splits the source file, parses the ns macro if found to do all the necessary transformations. Works on the body of namespace as text as simpler transformations are needed. When done puts the ns form and body back together.
(replace-ns-symbol-in-source-files old-sym new-sym extension dirs watermark)Replaces all occurrences of old-sym with new-sym in every Clojure source
file under dirs. extension is the moved namespace's file extension (used to
decide which files a rename applies to) and watermark the metadata key
stamped on the renamed ns. A single-rename convenience wrapper over
replace-ns-symbols-in-source-files.
Replaces all occurrences of `old-sym` with `new-sym` in every Clojure source file under `dirs`. `extension` is the moved namespace's file extension (used to decide which files a rename applies to) and `watermark` the metadata key stamped on the renamed ns. A single-rename convenience wrapper over `replace-ns-symbols-in-source-files`.
(replace-ns-symbols content renames file-ext)(replace-ns-symbols content renames file-ext java-classes)Applies a batch of renames to one file's content in a single pass: the ns
form is parsed once and the body scanned once, rather than once per rename.
renames is a seq of maps {:old-sym :new-sym :watermark :extension}. The
result is equivalent to folding replace-ns-symbol over the renames, but
O(file) instead of O(file x renames). java-classes (optional) are
fully-qualified repackaged Java class names left untouched in the body.
Applies a batch of `renames` to one file's `content` in a single pass: the ns
form is parsed once and the body scanned once, rather than once per rename.
`renames` is a seq of maps {:old-sym :new-sym :watermark :extension}. The
result is equivalent to folding `replace-ns-symbol` over the renames, but
O(file) instead of O(file x renames). `java-classes` (optional) are
fully-qualified repackaged Java class names left untouched in the body.(replace-ns-symbols-in-source-files renames dirs)(replace-ns-symbols-in-source-files renames dirs java-classes)Applies a batch of namespace renames to every Clojure source file under
dirs, reading and writing each file at most once (in parallel, per file).
renames is a seq of maps with :old-sym, :new-sym, :extension (the moved
namespace's file extension) and :watermark. A rename is applied to a given
file only when update? holds for that file and the rename's extension - the
same per-rename behaviour as applying the renames one at a time, but without
re-scanning the directories and re-reading every file once per rename.
java-classes (optional) are fully-qualified repackaged Java class names that
the rewrite must leave untouched (they are prefixed by the java-import pass).
Applies a batch of namespace renames to every Clojure source file under `dirs`, reading and writing each file at most once (in parallel, per file). `renames` is a seq of maps with `:old-sym`, `:new-sym`, `:extension` (the moved namespace's file extension) and `:watermark`. A rename is applied to a given file only when `update?` holds for that file and the rename's extension - the same per-rename behaviour as applying the renames one at a time, but without re-scanning the directories and re-reading every file once per rename. `java-classes` (optional) are fully-qualified repackaged Java class names that the rewrite must leave untouched (they are prefixed by the java-import pass).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |