Skip to content

Add magic requires - #4218

Merged
bbatsov merged 2 commits into
masterfrom
ns-magic-requires
Oct 24, 2026
Merged

bbatsov merged 2 commits into
masterfrom
ns-magic-requires

Conversation

@bbatsov

@bbatsov bbatsov commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

An opt-in take on clj-refactor's cljr-slash, which came up in #3356. With clojure-emacs/cider-nrepl#1062 it goes by the aliases the project already uses, and by cider-ns-magic-require-aliases alone with an older cider-nrepl. It hooks into post-self-insert-hook instead of binding the slash, so clj-refactor's binding wins where both are on.

@bbatsov
bbatsov force-pushed the ns-magic-requires branch 2 times, most recently from b7273f5 to dd2229a Compare October 23, 2026 05:53
clj-refactor's cljr-slash adds the require an alias needs as the alias
gets typed, and it's the clj-refactor feature people still ask for.
With cider-ns-magic-requires on (it's off by default), typing a slash
after an alias the ns form doesn't have does the same. The namespace
comes from cider-nrepl's cider/resolve-alias, which goes by the aliases
the project's source files use, and from cider-ns-magic-require-aliases
when the REPL can't tell. An entry there can name the platforms its
namespace works on, so io doesn't bring clojure.java.io into
ClojureScript.

It hooks into post-self-insert-hook rather than binding the slash, so
clj-refactor's binding keeps working where it's on. Since it runs while
the user types, the request gives up on the next keystroke, failures go
to the echo area, an error from evaluating the ns form doesn't select
the error buffer, and the require is an undo step of its own. Picking
nothing leaves the alias alone in that buffer from then on.
Magic requires go by the project's aliases through its cider/resolve-alias op.
@bbatsov
bbatsov merged commit de5a400 into master Oct 24, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant