Skip to content

Commit badf458

Browse files
committed
Fix bug when renaming ns aliases with common prefixes
1 parent 48dee72 commit badf458

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
@@ -2703,7 +2703,7 @@ lists up."
27032703
(defun clojure--rename-ns-alias-internal (current-alias new-alias)
27042704
"Rename a namespace alias CURRENT-ALIAS to NEW-ALIAS."
27052705
(clojure--find-ns-in-direction 'backward)
2706-
(let ((rgx (concat ":as +" (regexp-quote current-alias)))
2706+
(let ((rgx (concat ":as +" (regexp-quote current-alias) "\\_>"))
27072707
(bound (save-excursion (forward-list 1) (point))))
27082708
(when (search-forward-regexp rgx bound t)
27092709
(replace-match (concat ":as " new-alias))
@@ -2768,7 +2768,7 @@ With a numeric prefix argument the let is introduced N lists up."
27682768
(let* ((current-alias (completing-read "Current alias: "
27692769
(clojure-collect-ns-aliases
27702770
(save-excursion (thing-at-point 'list)))))
2771-
(rgx (concat ":as +" current-alias))
2771+
(rgx (concat ":as +" (regexp-quote current-alias) "\\_>"))
27722772
(bound (save-excursion (forward-list 1) (point))))
27732773
(if (save-excursion (search-forward-regexp rgx bound t))
27742774
(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)