Skip to content

Commit 67d5720

Browse files
author
Yannick Scherer
committed
add 'without-positional-zipper' and 'use-positional-zipper!'.
1 parent 3fa9d96 commit 67d5720

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/rewrite_clj/custom_zipper/core.clj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
implementation."
2828
false)
2929

30+
(defn use-positional-zipper!
31+
"Globally activate the position-tracking zipper. You can locally revert
32+
behaviour to `clojure.zip`'s by using `without-positional-zipper`."
33+
[]
34+
(alter-var-root #'*active?* (constantly true)))
35+
3036
(defmacro ^:private defn-switchable
3137
[sym docstring params & body]
3238
(let [placeholders (repeatedly (count params) gensym)]
@@ -46,6 +52,13 @@
4652
`(binding [*active?* true]
4753
~@body))
4854

55+
(defmacro without-positional-zipper
56+
"Force usage of `clojure.zip` to evaluate any rewrite-clj zipper operations in
57+
`body` instead of a custom position-tracking zipper."
58+
[& body]
59+
`(binding [*active?* true]
60+
~@body))
61+
4962
;; ## Implementation
5063

5164
(defn ^:no-doc zipper

src/rewrite_clj/zip.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
(import-vars
2525
[rewrite-clj.custom-zipper.core
2626
node position root
27-
with-positional-zipper]
27+
use-positional-zipper!
28+
with-positional-zipper
29+
without-positional-zipper]
2830

2931
[rewrite-clj.zip.base
3032
child-sexprs

0 commit comments

Comments
 (0)