Skip to content

Commit 2ff902b

Browse files
committed
Fix bug when renaming ns aliases with common prefixes
1 parent 41e124d commit 2ff902b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clojure-mode.el

+2-2
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ lists up."
27022702
(defun clojure--rename-ns-alias-internal (current-alias new-alias)
27032703
"Rename a namespace alias CURRENT-ALIAS to NEW-ALIAS."
27042704
(clojure--find-ns-in-direction 'backward)
2705-
(let ((rgx (concat ":as +" (regexp-quote current-alias)))
2705+
(let ((rgx (concat ":as +" (regexp-quote current-alias) "\\_>"))
27062706
(bound (save-excursion (forward-list 1) (point))))
27072707
(when (search-forward-regexp rgx bound t)
27082708
(replace-match (concat ":as " new-alias))
@@ -2767,7 +2767,7 @@ With a numeric prefix argument the let is introduced N lists up."
27672767
(let* ((current-alias (completing-read "Current alias: "
27682768
(clojure-collect-ns-aliases
27692769
(save-excursion (thing-at-point 'list)))))
2770-
(rgx (concat ":as +" current-alias))
2770+
(rgx (concat ":as +" (regexp-quote current-alias) "\\_>"))
27712771
(bound (save-excursion (forward-list 1) (point))))
27722772
(if (save-excursion (search-forward-regexp rgx bound t))
27732773
(let ((new-alias (read-from-minibuffer "New alias: ")))

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

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@
4343
(+ (foo/a 1) (b 2))"
4444

4545
(clojure--rename-ns-alias-internal "lib" "foo"))
46+
(when-refactoring-it "should handle multiple aliases with common prefixes"
47+
48+
"(ns foo
49+
(:require [clojure.string :as string]
50+
[clojure.spec.alpha :as s]
51+
[clojure.java.shell :as shell]))
52+
53+
(s/def ::abc string/blank?)
54+
"
55+
"(ns foo
56+
(:require [clojure.string :as string]
57+
[clojure.spec.alpha :as spec]
58+
[clojure.java.shell :as shell]))
59+
60+
(spec/def ::abc string/blank?)
61+
"
62+
(clojure--rename-ns-alias-internal "s" "spec"))
4663

4764
(when-refactoring-it "should handle ns declarations with missing as"
4865
"(ns cljr.core

0 commit comments

Comments
 (0)