52 lines
1.3 KiB
VimL
52 lines
1.3 KiB
VimL
vim9script
|
|
|
|
def GetMatch(base: string, line: string, add_base: bool): list<any>
|
|
var s = base
|
|
while stridx(line, s) == -1
|
|
s = strpart(s, 1)
|
|
if strlen(s) == 0
|
|
return [0, ""] # vim ignores these
|
|
endif
|
|
endwhile
|
|
const idx = stridx(line, s)
|
|
const slen = strlen(s)
|
|
if add_base
|
|
return [slen, base .. strpart(line, idx + slen)]
|
|
else
|
|
return [slen, strpart(line, idx + slen)]
|
|
endif
|
|
enddef
|
|
|
|
def LineSuffixCompl(findstart: bool, base: string): any
|
|
if findstart
|
|
return 0
|
|
endif
|
|
return getbufinfo()
|
|
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
|
|
->flattennew()
|
|
->sort()
|
|
->uniq()
|
|
->map( (_, v) => GetMatch(base, v, v:true) )
|
|
->sort( (x, y) => y[0] - x[0] )
|
|
->map( (_, v) => v[1] )
|
|
enddef
|
|
|
|
def DoLSCmpl(): string
|
|
const base = getline('.')
|
|
const lines = getbufinfo()
|
|
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
|
|
->flattennew()
|
|
->sort()
|
|
->uniq()
|
|
->map( (_, v) => GetMatch(base, v, v:false) )
|
|
->sort( (x, y) => y[0] - x[0] )
|
|
->map( (_, v) => v[1] )
|
|
|
|
complete(col('.'), lines)
|
|
return ''
|
|
enddef
|
|
|
|
# inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
|
|
|
|
set completefunc=LineSuffixCompl
|