Comments (4)
I'm curious why the defcustom should still be an alist prefixed by the namespace refer. If the intention is to send the entire defcustom to the middleware, can't we parse the recommended as target in the middleware? I wonder if we could make it a list of the recommendation string with a list of valid language contexts, where a nil list indicates all language contexts are allowed.
(defcustom cljr-magic-require-namespaces
'(("clojure.set :as set")
("clojure.java.io :as io" ("clj"))
("foo.io :as io" ("cljs"))
("clojure.string :as str")
("clojure.walk :as walk")
("clojure.zip :as zip")))
In the future this could support examples where the recommended namespace contained a refers or a reader conditional. Ie an example like: '("clojure.set :refer [union] :as set")
. I could also imagine prefixing the restrictions with a keyword like :include
/:exclude
, or :only
/:except
to account for the other language contexts possibilities. Ie something like: ("clojure.java.io :as io" :only ("clj"))
or ("foo.io :as io" :except ("clj"))
.
As a reminder, while I think the majority of users are only encountering this with cljc, cljs, and clj, the official docs for reader conditionals includes cljr
, and default
, and while I haven't encountered it in the wild, Babashka does supports :bb
. Even if those are not yet supported by this functionality, I think it makes sense to assume future compatibility will be desired.
This would not be quite as compatible with the existing format, but I think it allows for more flexibility moving forward.
from clj-refactor.el.
In the future this could support examples where the recommended namespace contained a refers or a reader conditional.
While desiring such a thing makes sense, I'd like to favor a different approach: real project usage (i.e. whatever you have in your namespace files) is the ultimate indication to refactor-nrepl of what is intended.
This is more concise (you have to declare very few, basic preferences), and more flexible (goes on a per-project basis; their different customs don't get mixed up). We also don't require a migration path for users (which can be hard to communicate IME).
It also goes well with the CIDER's overall philosophy of gathering insights at runtime, instead of requiring extensive, upfront, static configuration.
I'm not definitely closing the door to this feature, but in the end, making the middleware accept more inputs (e.g. a new defcustom, while the old one remains acceptable) is not a breaking change.
Thanks!
from clj-refactor.el.
I think on further reflection, the major concern I have about this, despite it being backwards compatible is that it feels like a very unintuitive syntax to encounter in Emacs without any context. I'm struggling to think of any other API I've seen using a syntax like this? It's not discoverable without specifically reading the docs for the defcustom (which I'm not sure we can fix), but more importantly if I saw it in the wild I don't know as I would intuitively understand that it was limiting it to those contexts.
What if we use keyword like :only
to help indicate intent:
(defcustom cljr-magic-require-namespaces
'(("set" . "clojure.set")
("io" "clojure.java.io" :only ("clj"))
("io" "foo.io" :only ("cljs"))
("str" . "clojure.string")
("walk" . "clojure.walk")
("zip" . "clojure.zip")))
I believe that is still backwards compatible, but I think that might be easier to follow at first glance? It would also support adding :exclude
at some future point, while still maintaining compatibility. Let me know what you think.
from clj-refactor.el.
Sounds good, let's go for it 👍
from clj-refactor.el.
Related Issues (20)
- cljr-clean-ns erroneously removes :as-alias in clj namespaces HOT 1
- Document (or remove) pkg-info dependency HOT 6
- `cljr-sort-project-dependencies` drop :dependencies section when using managed-dependencies HOT 2
- cljr-slash magic require js/ behavior is determined by file type, not language context HOT 2
- cljr--ns-alias-at-point does not handle quasiquote, sharp-quote and dotted aliases HOT 1
- Combine cljs and clj namespace alias candidates for magic requires HOT 15
- Create cljr-slash variant that uses the `suggest-libspecs` middleware op HOT 9
- `cljr--point-in-reader-conditional-branch-p` may block and is incorrect HOT 1
- Question: how to install `clj-refactor` via `use-package` declaration instead of imperative `package-install`? HOT 2
- Enhancement: trying to install and configure `clj-refactor` with the declarative `use-package` instead of imperative `package-install` HOT 1
- cljr-add-project-dependency throws `java.io.EOFException` HOT 6
- `cljr-rename-symbol` not working properly when narrowing is in effect HOT 2
- cljr-slash breaks whenever there's a Unicode character used as an alias in a codebase HOT 3
- cljr-add-project-dependency document support for deps.edn HOT 1
- Add Emacs 28, 29 to test matrix
- Add `eldev lint` to the CI
- Some refactorings are not working via TRAMP HOT 2
- Add support for updating :sha in :git/url dependencies HOT 3
- Error with suggest_libspecs HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clj-refactor.el.