initial version to replace line completion
This commit is contained in:
parent
4e887415c1
commit
ec4c119181
29
lc.vim
29
lc.vim
@ -1,16 +1,20 @@
|
||||
vim9script
|
||||
|
||||
def GetMatch(base: string, line: string): list<any>
|
||||
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, ""]
|
||||
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
|
||||
@ -22,9 +26,26 @@ def LineSuffixCompl(findstart: bool, base: string): any
|
||||
->flattennew()
|
||||
->sort()
|
||||
->uniq()
|
||||
->map( (_, v) => GetMatch(base, v) )
|
||||
->map( (_, v) => GetMatch(base, v, v:true) )
|
||||
->sort( (x, y) => y[0] - x[0] )
|
||||
->map( (_, v) => v[1] )
|
||||
enddef
|
||||
|
||||
setlocal completefunc=LineSuffixCompl
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user