meow icon indicating copy to clipboard operation
meow copied to clipboard

`meow-pop-selection` should undo `meow-cancel-selection`

Open axgfn opened this issue 1 year ago • 4 comments

I was looking for an analog to vim's gv command that re-selects the most recent selection, and I couldn't find one. I rely on this feature in vim and I think it would be even more useful in meow given how much more meow relies on selections.

Probably the most logical place to add this functionality in meow is as a fallback behavior when meow-pop-selection is called without a selection.

axgfn avatar Mar 19 '23 19:03 axgfn

The selection histories are stored with their positions, once a modification is made, the histories become inaccurate. This is why we drop histories when selection is deactivated.

DogLooksGood avatar Mar 20 '23 02:03 DogLooksGood

OK, but what about when no modification has been made? One thing I find happening a lot as I try to adjust to meow is that I'll start selecting something, then accidentally start a new selection (when I wanted to extend the old one), but there is already no way to undo my mistake. I have to start my selection over again from scratch.

axgfn avatar Mar 20 '23 05:03 axgfn

It's possible, of course, but I don't think it's a good idea. Two reasons:

  1. It's a little bit hard for people to remember whether a modification was made or not.
  2. It's hard for Meow to track the modification, unless we use the hook, and we are trying to avoid hooks as much as possible.

I used to have a concept in my mind to make all "single-key" mistake recoverable, by designing all commands in a compatible way. But in the end, I found it introduces a lot complexity.

And in your case, a simple idea is, don't extend the selection. When making a selection, you should describe where you want to go(e.g. after a specific char, end of a symbol, a paired parentheses, etc), instead of describing the path(e.g. line+word+char*3). Whenever you need a arbitrary extending, you use built-in commands, M-f, M-b, C-e, etc.

DogLooksGood avatar Mar 21 '23 14:03 DogLooksGood

Would you still be open to accepting this feature if someone could find and PR a simple way to do it? I also really feel the need for it. It's often not possible to specify a complex selection with Meow's thing commands (example - select the next 3 paragraphs), and it's very easy to lose a carefully made selction in Meow since so many commands cancel it.

As an example of a possible approach, though I haven't tried yet, I think it could be done by using markers to save the selection positions in meow--selection and meow--selection-history; these will move when the buffer is modified, so the position of the selection would remain relatively accurate regardless of changes to that region. This is how Evil does it (see evil-visual-restore).

45mg avatar May 19 '24 02:05 45mg