-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zip/right does not skip over uneval nodes #70
Comments
We now have our own versions of left/right/next that all correctly jump over uneval nodes, in particular we want to avoid descending into uneval subtrees (as they may contain gibberish), or call sexp on an uneval node (as that will outright fail). See clj-commons/rewrite-clj#70
We now have our own versions of left/right/next that all correctly jump over uneval nodes, in particular we want to avoid descending into uneval subtrees (as they may contain gibberish), or call sexp on an uneval node (as that will outright fail). See clj-commons/rewrite-clj#70
@xsc could you comment on this? would you consider accepting a PR that changes this behavior? In Depot we now have our own versions of left/right/next all to deal with uneval nodes. Every time we accidentally use |
Hi @plexus, since this could break things like code formatters, do you think it should it be an option when creating the zipper? |
The first question is if it's a bug or a feature. If it's a bug then I think the right thing to do is to add a If it's a feature then we'll just continue to work around it outside of |
I would also prefer to have the behavior of uneval being skipped if comments are configured to be skipped. On a related note, I'm investigating the idea of a zipper that doesn't skip comments but does skip whitespace. Is a general mechanism for tweaking / configuring what is skipped at zipper-creation time of any interest? |
What if one wanted to rewrite the uneval nodes? |
What if one wanted to rewrite comments? |
The difference from a Clojure perspective between |
Sure, but from a code semantics perspective it's as if these nodes don't exist. These rewrite-clj zipper operations are higher level operations over the lower level plain clojure zipper, that allow you to work with code at a more semantic level. If you care about more than that then go a level lower and use plain zipper operations. If the zipper doesn't jump over uneval nodes then consumers need to check for them at every single step, thus creating wrapper functions for all zipper navigation functions. Every consumer will have to do this, and every consumer will at first not realize until they get bitten by this. But... the ship has sailed at this point I think. This issue is 2.5 years old, and even back then this API probably already had too much real-world use to still tinker with the semantics. I don't think it makes sense to change it now for existing consumers, the only option would be to add an option or a parallel set of operations that handle these different cases. Maybe it would be possible to specify which behaviour you want when constructing the zipper initially. |
@plexus I was merely stating an observation, not an opinion. Adding an option to exclude certain types of nodes might be nice. Maybe this could be made more general than only |
Now that rewrite-clj has risen from its long slumber, I am excited that we will be able to actually do something here. The idea voiced by @sogaiu & @plexus of specifying something at zipper creation makes sense to me. And @borkdude's idea of a predicate on the We'll have to decide if the predicate describes what you'll see or what you'll skip. Another option is a predicate on the The default predicate would match current rewrite-clj behavior, but we could provide predefined predicates, starting with one that skips uneval nodes too. If that would save users some typing/errors, not sure, would have to experiment. The raw navigation fns ( |
Thinking ahead, I think it might be best to add an option map, not just a predicate, to allow for more options.
|
Yes, good point, zipper creation fns already have an option map, we'd add our predicate to it. |
I ran into this myself in this issue: babashka/babashka#825 |
Some old notes from me transcribed from Slack 2021-05-13:
|
And from 2022-02-24 in response to a query:
See above. In short: a little more thinking is required. |
rewrite-clj.zip/right
skips over whitespace, comments, commas, newlines, but does not skip over uneval nodes.I thought this was quite surprising. Is this intentional?
The text was updated successfully, but these errors were encountered: