Kakoune: Ability to discard selections with -itersel

Created on 6 Apr 2019  Â·  5Comments  Â·  Source: mawww/kakoune

Example – Keep one selection out of two (keep-even):

evaluate-commands -itersel %{
  evaluate-commands %sh{
    if test $((kak_main_reg_hash % 2)) != 0; then
      printf fail
    fi
  }
}

Most helpful comment

I think it could make sense for -itersel to swallow exclusively the "no selection remaining" failures by just removing the current selection from the set. Other failures should still propagate, and ending with no selections at all should still trigger a "no selection remaining" exception.

All 5 comments

I don't think swallowing failures is a good idea. Perhaps a delete-selection command which can be run inside an itersel block?

For this particular use case, which seems really useful, what about zero-width assertions in the regular expressions? This would make <a-k> more powerful. IIRC, Vim has some for asserting the file column and such.

And getting even more specific, I don't think <a-k> or <a-K> use their counts. Maybe this is what they should do? 2<a-k><ret> keeps every other selection.

Usually when an error occurs on a selection the selection discards itself.

Example – Selecting _bar_ words:

[foo] [bar]
execute-keys s(bar)<ret>
foo [bar]

Example – Trimming selections:

[foo¬]
[¬]
[bar¬]
execute-keys _
[foo]

[bar]

Example – Select the next word:

some [foo]
some [bar]
some [baz]
execute-keys e
some foo
[some] bar
[some] baz

I think it could make sense for -itersel to swallow exclusively the "no selection remaining" failures by just removing the current selection from the set. Other failures should still propagate, and ending with no selections at all should still trigger a "no selection remaining" exception.

To notice ending with no selections at all preserves the initial selection set.

@alexhebro2 it should trigger a "no selection remaining" exception (and probably preserve the initial selection set).

@mawww OK, after thinking about this, it works to handle "no selection remaining". I think I've written commands that will throw a "no selection remaining" in an error case without catching and throwing something more descriptive... but I don't think it happens often and would confuse the user.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fennewald picture fennewald  Â·  3Comments

hwmack picture hwmack  Â·  4Comments

akkartik picture akkartik  Â·  3Comments

valerdi picture valerdi  Â·  4Comments

MasterOfTheTiger picture MasterOfTheTiger  Â·  4Comments