-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feature Request: script modifier / rewrite properties #25
Comments
This would definitely be a great enhancement! However adding a bunch of rewrite properties is very limited, you can only use a predefined set of simple functions. And use full power of Lua scripting is an overkill. An observation is that these rewrite properties only apply to leaf nodes, like an identifier or quoted string. Texts of leaf nodes are not structured, so I cannot use structured edits. However this is what vim’s really good at. I want to make ssr.nvim can call vim’s built commands, so I can use gu for toLowerCase and backtick to toggle case. I also want to call commands from plugins, so I can use dial.nvim to change more complicated text cases. I can use the same technique I’m already familiar with in vim. No need to learn ssr.nvim specific functions. Lastly, I’m thinking about a “structural macro recording” feature, where ssr.nvim translates ”big” changes to structural replace and keeps “in-leaf-node” edits. Making ssr.nvim uses vim commands instead of predefined properties or Lua scripts also fits well in this situation. (Just some thoughts, I don’t think I have energy to implement anything recently 😢) |
If I understand correctly you'd want something like an enhanced macro that records keypresses/commands on tree-sitter nodes and replays those on every structural edit? Maybe an example (in Python, but doesn't really matter): one = (1, "one")
two = (2, "two") I want to switch the position of two values in a tuple and at the same time make the variable name uppercase. With Comby-like rewrite properties I can imagine something like this
How would the macro approach look like for the same? Where/when would I record the macro? I am not sure it would be easy to capture what is a structural edit and what is a regular edit? |
wrote a PR for using lua expressions in the REPLACE field #39 I wrote it before reading the discussion here, but I just want to leave some thoughts here.
|
As described here, in structural replace it is possible to apply small script modifiers to values. For example,
Field.name.toLowerCase()
turns the matched value into lower-case and then replaces it.It would be nice if this was possible in ssr.nvim with lua scripts or to have something like Comby's rewrite properties.
The text was updated successfully, but these errors were encountered: