clojure-emacs / clojure-emacs/clj-refactor.el

Ability to specify context in `cljr-magic-require-namespaces`

Open
#530 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Emacs Lisp
Stars
785
Forks
110
PR merge metrics
No merged PRs in 30d

Description

`cljr-magic-require-namespaces` doesn't currently allow specifying its intended context (:clj, :cljs).

This can easily cause incorrect suggestions for cljr-slash.

I'd suggest one of the following:

* Introduce new defcustom, e.g. `cljr-jvm-magic-require-namespaces`
* This would be a list like `'("clojure.java.io")`, specifying which values of `cljr-magic-require-namespaces` are intended for JVM clojure.
* Same for cljs
* **(Preferred)** Allow cljr-magic-require-namespaces to also include lists
* Example difference:

```diff
(defcustom cljr-magic-require-namespaces
'(("set" . "clojure.set")
- ("io" . "clojure.java.io")
+ ("io" "clojure.java.io" "clj")
+ ("io" "foo.io" "cljs")
("str" . "clojure.string")
("walk" . "clojure.walk")
("zip" . "clojure.zip")))
```

i.e. we could mix and match cons cells (`("set" . "clojure.set")`) with lists having the extra property `("io" "clojure.java.io" "clj")`.

Both approaches are intended to be backwards-compatible.

## Notes on semantics

* There are two values that must be expressible: clj, cljs
* cljc would be a no-op (since by default, entries already are context-agnostic)
* A value such as `"io" "clojure.java.io" "clj"` is intended to mean "please only _possibly_ suggest clojure.java.io if the filename is .clj"
* It does not, however, mean "clojure.java.io is the _only_ acceptable completion if the filename is .clj"
* refactor-nrepl is ultimately responsible for deciding what choice(s) will be offered.

## Final decision

https://github.com/clojure-emacs/clj-refactor.el/issues/530#issuecomment-1221624825

Contributor guide

Open the contributing guide

Research direction

Inspect the implementation of `cljr-magic-require-namespaces` and the `cljr-slash` suggestion path, then review the linked final-decision comment. Preserve existing entry forms while supporting context-specific `clj` and `cljs` entries; done means suggestions respect the filename context without treating a contextual entry as the only completion.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, emacs-lisp
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.