cursorless-dev / cursorless

Don't let the cursor slow you down
https://www.cursorless.org/
MIT License
1.14k stars 79 forks source link

Add support to repeat commands #378

Open AndreasArvidsson opened 2 years ago

AndreasArvidsson commented 2 years ago

Tokens and selection are treated on a text level take air three times => Selects the token air and the next two instances of the same text clear this twice => Clears the current selection and the next instance of the same text take first word twice => Selects the first sub word and the next instance of the same text take air past bat twice => Selects the range and the next instance of the same text

More complex scope and selection types are treated by order take line air twice => Selects the line containing air and the next line below take funk twice => Selects the current function and the next one below

To make this implementation feasible we probably need the new object oriented targets.

In the meantime there is an "ad hoc" solution to try: https://github.com/AndreasArvidsson/andreas-talon/blob/master/apps/vscode/vscode_take_word.talon

Ponderings:

AndreasArvidsson commented 2 years ago

Related to #30 Related to #29

pokey commented 2 years ago

Ok so one thought I had was that it may be action-dependant rather than just scope type dependant. For example, if a user implements the Paredit "slurp" command via custom commands (or if we implement it in the future) if they say "slurp air three times", the logical thing is that it slurps the next three forms, but I don't think there's any scope type information that we could use to infer that as the desired behaviour

AndreasArvidsson commented 2 years ago

That one is a bit harder. But I don't think that the reason it won't work for exactly everything is a good reason to not implemented it?

pokey commented 2 years ago

Well the problem is that it will shadow that command. It just feels like an indication that we don't yet fully understand this one. We both landed on the notion that it is action-independent, but this counterexample tells me it needs some more thought

Here's another example: "pour line three times". According to the logic we have here, that would create a newline after each of the next three lines. But again that isn't what I'd expect. I'd expect three new lines below the current line.

pokey commented 2 years ago

So I think fundamentally any solution here would need to look at both the action and the targets

pokey commented 2 years ago

What could make sense is to introduce a few target-action specific implementations, and fall back to basic repeater otherwise

AndreasArvidsson commented 2 years ago

I have no objections that the implementation needs to be aware of the action. Everything to make it as intuitive and fluent as possible.

pokey commented 2 years ago

Also worth thinking about how much this stuff overlaps with the "take next two funk" grammar, because I think that grammar is fairly unambiguous so may be preferable in certain situations

AndreasArvidsson commented 2 years ago

Yes in many cases it does the same thing.