@@ -2683,6 +2683,22 @@ lists up."
2683
2683
(insert sexp)
2684
2684
(clojure--replace-sexps-with-bindings-and-indent)))
2685
2685
2686
+ (defun clojure-collect-ns-aliases (ns-form )
2687
+ " Collect all namespace aliases in NS-FORM."
2688
+ (with-temp-buffer
2689
+ (delay-mode-hooks
2690
+ (clojure-mode)
2691
+ (insert ns-form)
2692
+ (goto-char (point-min ))
2693
+ (let ((end (point-max ))
2694
+ (rgx (rx " :as" (+ space)
2695
+ (group-n 1 (+ (not (in " ,]\n " ))))))
2696
+ (res ()))
2697
+ (while (re-search-forward rgx end 'noerror )
2698
+ (unless (or (clojure--in-string-p) (clojure--in-comment-p))
2699
+ (push (match-string-no-properties 1 ) res)))
2700
+ res))))
2701
+
2686
2702
(defun clojure--rename-ns-alias-internal (current-alias new-alias )
2687
2703
" Rename a namespace alias CURRENT-ALIAS to NEW-ALIAS."
2688
2704
(clojure--find-ns-in-direction 'backward )
@@ -2746,15 +2762,17 @@ With a numeric prefix argument the let is introduced N lists up."
2746
2762
(defun clojure-rename-ns-alias ()
2747
2763
" Rename a namespace alias."
2748
2764
(interactive )
2749
- (let ((current-alias (read-from-minibuffer " Current alias: " )))
2750
- (save-excursion
2751
- (clojure--find-ns-in-direction 'backward )
2752
- (let ((rgx (concat " :as +" current-alias))
2753
- (bound (save-excursion (forward-list 1 ) (point ))))
2754
- (if (save-excursion (search-forward-regexp rgx bound t ))
2755
- (let ((new-alias (read-from-minibuffer " New alias: " )))
2756
- (clojure--rename-ns-alias-internal current-alias new-alias))
2757
- (message " Cannot find namespace alias: '%s ' " current-alias))))))
2765
+ (save-excursion
2766
+ (clojure--find-ns-in-direction 'backward )
2767
+ (let* ((current-alias (completing-read " Current alias: "
2768
+ (clojure-collect-ns-aliases
2769
+ (thing-at-point 'list ))))
2770
+ (rgx (concat " :as +" current-alias))
2771
+ (bound (save-excursion (forward-list 1 ) (point ))))
2772
+ (if (save-excursion (search-forward-regexp rgx bound t ))
2773
+ (let ((new-alias (read-from-minibuffer " New alias: " )))
2774
+ (clojure--rename-ns-alias-internal current-alias new-alias))
2775
+ (message " Cannot find namespace alias: '%s ' " current-alias)))))
2758
2776
2759
2777
(defun clojure--add-arity-defprotocol-internal ()
2760
2778
" Add an arity to a signature inside a defprotocol.
0 commit comments