@@ -2683,6 +2683,22 @@ lists up."
26832683 (insert sexp)
26842684 (clojure--replace-sexps-with-bindings-and-indent)))
26852685
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+
26862702(defun clojure--rename-ns-alias-internal (current-alias new-alias )
26872703 " Rename a namespace alias CURRENT-ALIAS to NEW-ALIAS."
26882704 (clojure--find-ns-in-direction 'backward )
@@ -2746,15 +2762,17 @@ With a numeric prefix argument the let is introduced N lists up."
27462762(defun clojure-rename-ns-alias ()
27472763 " Rename a namespace alias."
27482764 (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)))))
27582776
27592777(defun clojure--add-arity-defprotocol-internal ()
27602778 " Add an arity to a signature inside a defprotocol.
0 commit comments