cursorless
cursorless copied to clipboard
Add "between" modifier
Will take a list of targets and select ranges between each adjacent target. So for example, in the following:
LANGUAGES = agda c clojure cpp css c-sharp bash go haskell html java javascript json latex markdown php python ruby rust scala scss sparql tsx typescript yaml
You could say "clear between every paint tail gust"
(where "gust"
refers to agda
) to select the whitespace between each "paint". Useful for breaking them onto new lines.
Note that this is similar to "clear leading every paint tail gust"
, but doesn't get the first leading whitespace
Will be a bit challenging to implement using today's exact setup, because each modifier only sees a single target from its input, so we'll need #756
Also note that there is grammar conflict with today's "between": "take line between bat" could interpret "between" as range connective or the proposed "between" modifier. Note that today's "between" connective could be accomplished with this proposed mofier: "take air between bat" will be equivalent to "take between air and bat". The latter is more verbose, but arguably cleaner grammatically.
If the use case is to break them into individual lines post
followed by enter
works just as well. If you don't have a formatter you might need to do a deletion to get rid of the superfluous whitespace. Is there a more practical application of this modifier?
No that isn't quite right, because you'll have an extra enter at the end, tho as you suggest autoformatter should handle that. Another example would be putting dashes between, but I guess kebab does that. Idk I'm not sure I have a completely killer use case yet, but it feels like something we'll want. Maybe let's leave open for a bit to see if we find ourselves wanting it again
Sounds good. I don't think the implementation will be that hard so if we have a good use case I can knock this one out fairly easy.
How do you get around https://github.com/cursorless-dev/cursorless/issues/756?
- Make it so that all modifier stages takes an array of target as input.
run(context, targets: Target[]): Target[]
- Make a base class
SingleTargetModifierStage
that just runs them all through the abstractrunSingleTarget(context, target: Target): Target[]
method. All our current modifiers use this. - Make a new modifier that looks at all the input target at once and creates new targets with the ranges between them.
Huh interesting idea. I'm hesitant to diverge from jq, but your proposal is compelling in its simplicity 🤔
relevant slack thread:
what's the fastest way to go from
1 2 3 4 5
to1, 2, 3, 4, 5
.post every token comma
puts a comma after the 5. Is there anything better thanpost every token 1 until 5 comma
?