Why are these completions replacing text before the anchor?

Hi All,

I’m not sure what I’m doing wrong here, I’ve been through the info in this thread and everything looks right to me, but the behavior is not what I was expecting.

Kak file defining some representative completions

decl completions test_completions

def -override enable_test_completions %{
  set-option window completers option=test_completions %opt{completers}
}

def -override test_one %{
  # Line one should be "Unix.sleep"
  set-option window test_completions "1.6+5@%val{timestamp}" "sleep||sleep" \
     "sleepf||sleepf"
}

def -override test_two %{
  # Line two should be "Kak.send"
  set-option window test_completions "2.5+4@%val{timestamp}" "send||send" \
    "setup_recv_sync||setup_recv_sync" "setup_send_async||setup_send_async" \
    "setup_send_sync||setup_send_sync" "squote||squote"
}

If I edit a file with these contents:

Unix.sleep
Kak.send

Run these commands
:source test.kak, :enable_test_completions, :test_one

Put the cursor here

Unix.sleep
     ^

and select the second completion sleepf I end up with

sleepfsleep
Kak.send

If I shorten the completion length by 1 to 1.6+4 I get

Unix.sleepfp
Kak.send

Note the trailing extra p

Thanks

I can reproduce this behaviour:

  • I saved the Kakoune script as test.kak

  • I saved the example buffer as buffer.txt

  • I launched Kakoune with:

    kak -n \
        -E "source test.kak" \
        -e "enable_test_completions; test_one; select 1.6,1.6; exec i" \
        buffer.txt
    

I think what you’re trying to do is “if the user enters insert mode anywhere inside the text ‘sleep’, replace the entire word with the text from the completions option”.

Unfortunately, Kakoune’s completions don’t quite work like that; it’s intended that hitting “insert” inside a word will never change text to the right of the cursor. That is, the optional “length” field is supposed to cover the span from the beginning of the completion to the cursor, and nothing past that.

Given the test case above, if you have the same completions option but you go into insert mode at the end of the line (just past the character pointed to by the start-coordinate plus the length) then the completions work fine.

I couldn’t find an existing issue in the Kakoune GitHub, but certainly the documentation could be made clearer at least.