cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

Add "between" modifier

Open pokey opened this issue 2 years ago • 6 comments

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.

pokey avatar Jun 08 '22 14:06 pokey

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?

AndreasArvidsson avatar Jun 29 '22 17:06 AndreasArvidsson

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

pokey avatar Jun 29 '22 18:06 pokey

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.

AndreasArvidsson avatar Jun 29 '22 18:06 AndreasArvidsson

How do you get around https://github.com/cursorless-dev/cursorless/issues/756?

pokey avatar Jun 29 '22 18:06 pokey

  1. Make it so that all modifier stages takes an array of target as input. run(context, targets: Target[]): Target[]
  2. Make a base class SingleTargetModifierStagethat just runs them all through the abstract runSingleTarget(context, target: Target): Target[]method. All our current modifiers use this.
  3. Make a new modifier that looks at all the input target at once and creates new targets with the ranges between them.

AndreasArvidsson avatar Jun 29 '22 19:06 AndreasArvidsson

Huh interesting idea. I'm hesitant to diverge from jq, but your proposal is compelling in its simplicity 🤔

pokey avatar Aug 03 '22 12:08 pokey

relevant slack thread:

what's the fastest way to go from 1 2 3 4 5 to 1, 2, 3, 4, 5. post every token comma puts a comma after the 5. Is there anything better than post every token 1 until 5 comma?

josharian avatar Jul 13 '23 21:07 josharian