From the vim documentation
FUNCTIONS FOR FINDING COMPLETIONS *complete-functions*
This applies to 'completefunc' and 'omnifunc'.
The function is called in two different ways:
- First the function is called to find the start of the text to be completed.
- Later the function is called to actually find the matches.
On the first invocation the arguments are:
a:findstart 1
a:base empty
The function must return the column where the completion starts. It must be a
number between zero and the cursor column "col('.')". This involves looking
at the characters just before the cursor and including those characters that
could be part of the completed item. The text between this column and the
cursor column will be replaced with the matches.
Special return values:
-1 If no completion can be done, the completion will be cancelled with an
error message.
-2 To cancel silently and stay in completion mode.
-3 To cancel silently and leave completion mode.
The function will be called twice and only the second time vim will interpret -1 as cancellation? Why?
I tested this with (version 8.0)
function! MyCompletion(findstart, base)
echomsg "Call MyCompletion" a:findstart
if a:findstart
return -1
endif
" return -1
return ["foo", "abc", "123"]
endfunction
So if I can not find a start for completion I have to use a nonlocal variable to remember this or test again?
if findstart
if test
s:completion_failed = 1
return whatever
endif
endif
if s:completion_failed
return -1
endif