Skip to content

Scoping issues with clojure-rename-ns-alias #531

Closed
@yuhan0

Description

@yuhan0

The new clojure-rename-ns-alias refactoring introduced in #529 should only modify namespaced symbols/keywords, but the current regexp is too broad and could unintentionally match with things like filenames and slashes used in prose to indicate choices.

I'm not sure what the expected behaviour should be, perhaps a good idea would be to skip matching of strings but not comments, since strings found in source code don't generally refer to interned symbols (apart from references in docstrings where the full unaliased namespaces would be used)

Another option might be to delegate matching strings and comments to query-replace so that such cases can be spotted and dealt with interactively.

Steps to reproduce the problem

(ns my.ns
  (:require [my.lib :as lib]))

(def dirname "/usr/local/lib/python3.6/site-packages")

;; TODO: refactor using lib/foo
(def data (lib/baz dirname))
  • Execute M-x clojure-rename-ns-alias lib RET new-lib RET

Result (note the invalid directory name):

(ns my.ns
  (:require [my.lib :as new-lib]))

(def dirname "/usr/local/new-lib/python3.6/site-packages")

;; TODO refactor using new-lib/foo
(def data (new-lib/baz dirname))

Environment & Version information

clojure-mode version information

clojure-mode (version 5.11.0-snapshot)

Emacs version

26.2

Operating system

macOS 10.14.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions