For issue #3336, I want to take each selection and pipe it to lintcmd
. However, a linter will return its line-numbers relative to the start of the selection, not the start of the buffer, so I need to rewrite the line and column-numbers in the output.
Sounds simple enough - as well as processing $kak_selections
, I’ll also grab $kak_selections_desc
and then I’ll know where each selection originally came from! Except, it’s not actually that simple:
- Start Kakoune with
seq 1 3 | kak -n
- Select all the digits in the buffer:
%s\d<ret>
- Examine the contents of each selection:
:echo %val{selections}
- yep, looks good:
'1' '2' '3'
- yep, looks good:
- Examine the coordinates of each selection:
:echo %val{selections_desc}
Uh oh:
3.1,3.1 1.1,1.1 2.1,2.1
…that is, %val{selections_desc}
always starts with the primary selection, no matter where it is in the document, while %val{selections}
seems to be in document order, regardless of which is the primary.
How can I get selections and descriptions in a consistent order? I know if I save a mark to a register, it stores the index of the main selection… but I don’t know if there’s any guarantees about the overall order of selections.