-
Notifications
You must be signed in to change notification settings - Fork 24
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
Tree sitter: transformation support #47
Tree sitter: transformation support #47
Conversation
all of these seem to work from initial inspection, but will keep playing with them. :D |
it might be time to add a symex-global-mode, or at least one that applies to any tree-sitter buffer |
@tommy-mor What would you like to see in such a mode? If it is just to prevent Lisp-style addition of spaces, for now we could do something like:
... in |
Looking good so far! Some observations:
|
@countvajhula Thanks for the feedback!
Yes there are a couple of issues like this. I need to think of a way to select a new node reliably after every transformation.
As you mentioned I think |
FYI @polaris64 and @tommy-mor the evil-repeat (dot) work has landed 😄 . Would probably be good to rebase the integration branch soon to level up - let me know whenever you'd like to do that @polaris64 . The tree-sitter transformations should automatically gain the dot functionality once that happens, since the repeat recording happens at the level of the public transformation interfaces and not the primitive layer (cf. |
@countvajhula woohoo! That's very exciting! I think it's a good idea to rebase the integration work as it will have to function with evil-repeat anyway. I haven't checked the diff yet so I'm not sure how much it conflicts with the TS changes made thus far, but if these are fairly minimal then I'd say go ahead. If they are more in depth then we'll probably have to rebase the current integration work and then I can start again on the transformation work. I haven't done a great deal so far, so applying the patches onto a new branch shouldn't be too much trouble. |
de0f5db
to
43d2a21
Compare
@polaris64 Ok I've rebased the symex-ts-integration branch. Locally, when I ran |
808ebd0
to
a61ec48
Compare
@countvajhula, sorry to sound like a broken record, but apologies for the lack of recent activity again. I have a lot of things going on both at home and at work so I have to use any spare moments I get as they arise! In any case, I've rebased this PR onto your upstream |
@polaris64 Yeah that sounds like a good way of going about it - checking off the list first and then tweaking the experience later. In fact at that stage we can probably get the help of users to test it (I think @tommy-mor is always up for trying things out!). Also, by way of signposting -- and this doesn't necessarily affect our current trajectory (unless you believe it should) -- but in the light of #26 , I'm thinking that eventually My further plan along these lines is to eventually start some kind of crowdfunding account for the drym-org github account, and then distribute any contributions via an attribution-based scheme, an early prototype of what's described at drym.org. (In reality, attribution should not be restricted to any particular account or initiative or group, but this could a rudimentary start that, with any luck, will prove the concept for broader adoption). I'm not sure when I'd get around to setting this up, but I wanted to give you an early heads up since it may involve some logistical stuff like moving repos around and whatnot, and I don't want that process to annoy you any more than necessary 😄 |
This all sounds fine to me, don't worry! :) I'm happy contributing what I can to the project so I don't mind how the project is managed. In terms of moving repos around, that's fine too. I've started reading your article on drym.org and it sounds interesting, so I'll be sure to read it more thoroughly when I get time. Thanks for the heads-up! |
* symex-transformations-lisp.el: new module to contain Lisp-specific transformations in the spirit of symex-primitives-lisp.el (WIP). * symex-transformations.el: (symex-delete) and (symex-delete-backwards): modify to use Lisp or TS variants based on `tree-sitter-mode`. * symex-ts.el: (symex-ts-delete-node-forward) and (symex-ts-delete-node-backward): new functions to provide TS versions of (symex-delete) and (symex-delete-backwards).
* Insert either a " " or "\n" before/after the pasted node based on the node's span. If it is multi-line or covers the entire line then insert a newline, otherwise insert a space. * Re-factor paste functions.
The new `symex-ts--handle-tree-modification` macro is an attempt to generalise how tree modifications are handled with respect (mainly) to selecting a new current node. This macro first saves the current tree, performs the transformation and then compares the newly modified tree. It attempts to find the first range that is marked as being modified and, if successful, moves the point to the start of that range. Regardless of the outcome, it then uses the point to select the current node and handles mode-specific indentation. `symex-ts--paste` has been modified to use this new macro. The hope is that this macro will also prove useful when implementing other transformations.
Overlay handling has now been moved into the core of Symex so make sure to call `symex--update-overlay` if the overlay is enabled in `symex-ts--handle-tree-modification`.
* Use `symex-ts--handle-tree-modification` in `symex-ts-delete-node-forward`. * `symex-ts-delete-node-forward`: add loop to delete all empty lines until next node if `keep-empty-lines` is unset. * `symex-ts--delete-current-line-if-empty`: return flag to indicate if a line was deleted.
89361d5
to
efeb80d
Compare
@countvajhula I've just rebased this PR onto the latest Perhaps you could test this PR a bit and see if you feel it's ready to merge? We can then create a branch for the remaining transformations. |
If BODY consists of multiple forms then the `let` binding would be invalid. Wrap BODY in `progn` to avoid such situations.
Looking great @polaris64 ! One issue that seemed to crop up in different ways was about selection. After entering text, or after doing a transformation of some kind, entering symex mode sometimes selected an unexpected expression. I suspect this can be solved at the level of Full results of my testing:
With point at
And yeah, I think the PR is fine to merge as is since it is introducing new things and doesn't break existing things. We can continue with the above fixes / remaining transformations in bite-sized follow-up PRs. I'll transfer the outstanding items directly into the integration PR description (or maybe try out GitHub Projects for this? I'll give it a look). Thanks! |
Summary of Changes
I have started work on implementing the transformations in
symex-transformations.el
with tree sitter.As with
symex-primitives
I have started moving the existing transformations to a newsymex-transformations-lisp.el
module and I have created a newsymex-transformations-ts.el
module for the new implementations. Once a transformation is implemented, I modify the appropriate function insymex-transformations.el
to dispatch to the correct implementation based on the value oftree-sitter-mode
.This is a work-in-progress! Only a few transformations have been implemented so far (see the list below). The purpose of this PR is therefore to track this work until the point at which it is deemed complete enough to merge to
symex-ts-integration
.Here are the transformations that I believe will need to be implemented; ticked items have been implemented in this PR: -
Public Domain Dedication
(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)