chrisosaurus / dodo

scriptable in place file editor
MIT License
4 stars 1 forks source link

Multiple cursors #24

Open phillid opened 7 years ago

phillid commented 7 years ago

Having dodo support multiple cursors within the same file could potentially be a useful feature. With the standard command set it doesn't prove very useful, but it would open the door to some more interesting commands that work on multiple cursors within the same file.

I did a quick mock-up in my cursors branch. Cursor manipulation seems to be working well.

Is this a desirable feature?

chrisosaurus commented 7 years ago

Very interesting idea, thanks for bringing this up.

I see multiple cursors as another view/implementation of looping, you are repeating a set of commands at different places.

Is multiple cursors better or worse than an actual looping construct?

I can see how multiple cursors are better for human interfaces when the cursors are visible (e.g. GUI text editors). Multiple-cursors are also interesting in that they are potentially simpler to reason about than looping, and may require fewer language features.

Do you have any ideas around the set of possible commands that could make this even more powerful?

I still mean to add the previously discussed features around searching. insert operations could also be useful, although they are expensive in their nature.

Dodo hasn't been a priority for me lately, but I still really want to see where it can go, so thank you for continuing this.

Looking over your changes they look good stylistically. I don't see any docs about the new command. I think you would also need to support removing cursors.

Since all movement is currently absolute (relative is still pending having time..) there might also have to be some logic for removing redundant cursors (if they land on the same position).

I'm interested in seeing where this goes.

phillid commented 7 years ago

I see multiple cursors as another view/implementation of looping, you are repeating a set of commands at different places. [...] Do you have any ideas around the set of possible commands that could make this even more powerful?

As my implementation stands, the cursors can only be used ("active") one-at-a-time. I originally had intentions for the multiple cursors to be used as read+write pairs. For example, placing cursor 1 at some source data, then placing cursor 0 at a destination, then telling dodo to copy 100 bytes from source to destination.

Have to agree that multiple-write support would no doubt be extremely useful too.

Multiple-cursors are also interesting in that they are potentially simpler to reason about than looping, and may require fewer language features.

Definitely agree here, but it has just occurred to me that there is also the problem of extensibility to consider.

I think you would also need to support removing cursors.

Definitely a must for when the implementation will support selecting more than one cursor at a time.

phillid commented 7 years ago

I've just finished a further rough proof of concept which allows operation on multiple cursors at once—currently up to 256, then it lazily bails if more are added.

This feature definitely holds a lot of potential. Until I integrate relative offsets, they will still not prove too useful. I think automating the addition of cursors might be useful too, for example, I'd imagine telling dodo to add x new cursors every y bytes starting from the current cursor position might be nice.

Even still, looking at the current behaviour and features of dodo, I'll admit I don't see anything that writing a simple wrapper around dodo would do. For example, it would be easy enough to use some shell script to generate as many dodo scripts as you want cursors and run them in succession.

chrisosaurus commented 7 years ago

The more I think about this, the more I am not so certain it will work. I'm also worried that multiple cursors will be confusing, as you can't "see" them.

I don't really see the advantage of multiple cursors over having the ability to loop over the same command set at different locations.

I think dodo will need looping anyway, say 'replace all occurences of X with Y'