-
Notifications
You must be signed in to change notification settings - Fork 200
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
RFC: Add a 'region' lens to make controlling spacing easier #244
base: master
Are you sure you want to change the base?
Conversation
I think the feature is really interesting, and would solve a lot of issues (although I'd be more in favor of eventually providing an API exposing the deleted elements so we can control them). I haven't given it too much thought, but I can't think of a case where it wouldn't be good to make the region behavior the default, instead of patching all the existing lenses. |
I just rebased this to latest master. I am a little hesitant to just change the behavior of |
Do all the tests pass if you change the default behavior? Also, does it make sense to keep |
So far, how deleted text is handled when entries are added to or removed from the tree was tightly bound up with how the tree was structured, because the subtree combinator [ .. ] controlled both: construction of new tree nodes and glomming deleted stuff together. In addition, the [ .. ] does the glomming based on the key of the tree node it constructs, so that deleting a node from hte middle of a number of nodes with the same key had the weird effect that entries tended to 'shift up'. The region combinator tries to address this, in that all it does is demarcate how deleted stuff should be glommed, and it does that based on the position in the input file, not on the value of a key. Syntactically, this is written as < l >, though other syntax, like 'region l', or '<< l >>' might be better. It would be great if this could also be used to indent new things the same as surrounding stuff, i.e. if we have a lens < l >* and we add en entry in the middle of it, if that would automatically mean that the new entry gets the indentation of one of the surrounding lines - that's not implemented yet. I would really like to see and hear how this does or does not address some of the spacing/indentation problems that people have been having, ideally demonstrated by a simple test.
Updated to make it possible to switch between the current behavior of It's expected that the tests for this PR fail as-is as I added a test that only works when |
Hi! In some rare cases the behavior is incorrect. It can be reproduced with 4 steps: remove a node, save, add a new node, save again. E. g. I created such a file (
Then I executed
After that
As you can see, formatting of the last line has changed, although I didn't modify it. |
This is not meant to be committed yet, but I would really appreciate feedback based on people's experimenting with these patches.
So far, how deleted text is handled when entries are added to or removed
from the tree is tightly bound up with how the tree was structured,
because the subtree combinator [ .. ] controlled both: construction of new
tree nodes and glomming deleted stuff together.
In addition, the [ .. ] does the glomming based on the key of the tree node
it constructs, so that deleting a node from hte middle of a number of nodes
with the same key had the weird effect that entries tended to 'shift up'.
The region combinator tries to address this, in that all it does is
demarcate how deleted stuff should be glommed, and it does that based on
the position in the input file, not on the value of a key.
Syntactically, this is written as < l >, though other syntax, like 'region
l', or '<< l >>' might be better.
It would be great if this could also be used to indent new things the same
as surrounding stuff, i.e. if we have a lens < l >* and we add en entry in
the middle of it, if that would automatically mean that the new entry gets
the indentation of one of the surrounding lines - that's not implemented
yet.
I would really like to see and hear how this does or does not address some
of the spacing/indentation problems that people have been having, ideally
demonstrated by a simple test.