Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renaming no longer renames shadowed vars.

  • Loading branch information...
commit 812d2fd1a3f779d1ba1aa15e061d0f0f52df40ec 1 parent 2fc30c9
@tcrayford tcrayford authored
View
6 src/clojure_refactoring/ast/zip.clj
@@ -16,3 +16,9 @@
(-> (find-node (ast-zip ast) expr)
zip/path))
+(defn zip-walk [zipper f]
+ "Performs a depth first walk over zipper, calling f on each sub-node."
+ (loop [loc zipper]
+ (if (zip/end? loc)
+ (zip/root loc)
+ (recur (zip/next (f loc))))))
View
17 src/clojure_refactoring/rename.clj
@@ -24,20 +24,17 @@
loc
(zip/replace loc (ast/symbol new-name))))
+(defn rename-non-shadowed-in-ast [new-sym node old-name]
+ (zip-walk (ast-zip node)
+ #(if (= (zip/node %) (ast/symbol old-name))
+ (rename-node % new-sym) %)))
+
(defn renaming-fn [old-var new-sym]
"Returns a function for renaming nodes"
(fn [node]
- (loop [loc (ast-zip node)]
- (cond (zip/end? loc)
- (zip/root loc)
-
- (= (zip/node loc) (ast/symbol (.sym old-var)))
- (recur (zip/next (rename-node loc new-sym)))
-
- :else
- (recur (zip/next loc))))))
+ (rename-non-shadowed-in-ast new-sym node (.sym old-var))))
(defn global-rename [ns old-name new-name]
- "Sends a list of alists to emacs for processing as renames"
+ "Sends a list of alists to emacs for processing as renames."
(let [old-var (ns-resolve ns old-name)]
(replace-callers old-var (renaming-fn old-var new-name))))
Please sign in to comment.
Something went wrong with that request. Please try again.