̶a̶u̶t̶o̶-pairs release

I’ve just released a plugins, pairs : GitHub - 42xel/pairs.kak: A simpler, manual version of auto-pairs

To make a long story short, it is a manual alternative to auto-pairs, which trades some frustrations for some other.

Namely, you have to be mindful of when and how you want pairs and how to move out of them, but you also have more control over them. It also currently lacks automatic indentation when adding linebreaks in pairs. Because of its simplicity (no hooks, no try catch, no hidden option), pairs should be easier to make stable than auto-pairs. For example, I had little to no trouble making the repeat option work. An other sizeable example, as far as I can tell, auto-pairs does not support multi selection (even on VsCode it is arguably broken). Pairs works no sweat with multi selection.

To give credits were credit’s due, I am still amazed by the amount of logic and beauty crammed into the barely more than 100 lines of code of auto-pairs, and it this code, and its authors, were definitely great inspiration and teacher writing this plugin.

for those here for a technical gem, I’m quite proud of how I dodge the try catch auto-pairs uses to account for both length 1 and longer selections.
auto-pairs, snippet from a hook right after having inserted the first symbol of a pair :

    # Action: Close pair
    execute-keys %arg{2}

    # Keep the track of inserted pairs
    increment-inserted-pairs-count

    # Move back in pair (preserve selected text):
    try %{
      execute-keys -draft '<a-k>..<ret>'
      execute-keys '<a-;>H'
    } catch %{
      execute-keys '<a-;>h'
    }

pairs achieving something similar without try catch or filter, making it much easier to operate on multi selection :

set-register l "%arg{1}"
    set-register r "%arg{2}"
    # TODO explain how selections function. Essentially, it depends on whether you are writing between the cursor and anchor.
    execute-keys -draft ';i<c-r>l'
    execute-keys -draft -save-regs '' 'H<a-;>H<a-;>Z\
;a<c-r>r'
    execute-keys -draft -save-regs '' 'zL<a-;>L<a-;>Z'

(I think this idea can be ported to auto-pairs)

3 Likes

we should probably try to standardize the subset of pairing commands that everyone agrees one.
Not so easy of course

2 Likes