Skip to content

Commit 1cce395

Browse files
committed
[Fix #531] Don't match strings when using clojure-rename-ns-alias.
1 parent fae40b9 commit 1cce395

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

clojure-mode.el

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,13 +2662,12 @@ lists up."
26622662
(clojure--find-ns-in-direction 'backward)
26632663
(let ((rgx (concat ":as +" current-alias))
26642664
(bound (save-excursion (forward-list 1) (point))))
2665-
(when (save-excursion (search-forward-regexp rgx bound t))
2666-
(save-excursion
2667-
(while (re-search-forward rgx bound t)
2668-
(replace-match (concat ":as " new-alias))))
2665+
(when (search-forward-regexp rgx bound t)
2666+
(replace-match (concat ":as " new-alias))
26692667
(save-excursion
26702668
(while (re-search-forward (concat current-alias "/") nil t)
2671-
(replace-match (concat new-alias "/"))))
2669+
(when (not (nth 3 (syntax-ppss)))
2670+
(replace-match (concat new-alias "/")))))
26722671
(save-excursion
26732672
(while (re-search-forward (concat "#::" current-alias "{") nil t)
26742673
(replace-match (concat "#::" new-alias "{"))))

test/clojure-mode-refactor-rename-ns-alias-test.el

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,44 @@
5555
5656
(+ (lib/a 1) (b 2))"
5757

58-
(clojure--rename-ns-alias-internal "foo" "bar")))
58+
(clojure--rename-ns-alias-internal "foo" "bar"))
5959

60-
(provide 'clojure-mode-refactor-rename-ns-alias-test)
60+
(when-refactoring-it "should skip strings"
61+
"(ns cljr.core
62+
(:require [my.lib :as lib]))
63+
64+
(def dirname \"/usr/local/lib/python3.6/site-packages\")
65+
66+
(+ (lib/a 1) (b 2))"
67+
68+
"(ns cljr.core
69+
(:require [my.lib :as foo]))
70+
71+
(def dirname \"/usr/local/lib/python3.6/site-packages\")
72+
73+
(+ (foo/a 1) (b 2))"
74+
75+
(clojure--rename-ns-alias-internal "lib" "foo"))
76+
77+
(when-refactoring-it "should not skip comments"
78+
"(ns cljr.core
79+
(:require [my.lib :as lib]))
80+
81+
(def dirname \"/usr/local/lib/python3.6/site-packages\")
82+
83+
;; TODO refactor using lib/foo
84+
(+ (lib/a 1) (b 2))"
85+
86+
"(ns cljr.core
87+
(:require [my.lib :as new-lib]))
88+
89+
(def dirname \"/usr/local/lib/python3.6/site-packages\")
90+
91+
;; TODO refactor using new-lib/foo
92+
(+ (new-lib/a 1) (b 2))"
93+
94+
(clojure--rename-ns-alias-internal "lib" "new-lib")))
95+
96+
(provide 'clojure-mode-refactor-rename-ns-alias-test)
6197

6298
;;; clojure-mode-refactor-rename-ns-alias-test.el ends here

0 commit comments

Comments
 (0)