line completion working

This commit is contained in:
2025-09-08 22:55:27 -04:00
parent c6e2d2a8f4
commit caa42275f6
2 changed files with 8 additions and 51 deletions

32
exp.txt
View File

@@ -1,32 +0,0 @@
fo
bar
bar
hello
bar
hello
hello
f
abcd
fo
hello
fo
bcd
hello world and ha ha ha
foo bar and ha ha ha
xdfadf bar and ha ha he
skafjds bar and ha ha ha
hello ha ha ha
foob and ha ha ha
skafjds bar and ha ha ha
fjds bar and ha ha ha
a b c and ha ha ha
var foo = SomeBigName(arg1, arg2, arg3)
var bar = SomeBigName(arg1, arg2, arg3)
var xyz = SomeBigName(arg1, arg2, arg3)
var xdf = Som

27
lc.vim
View File

@@ -22,14 +22,15 @@ def GetMatch(base: string, line: string, add_base: bool): Item
endif
enddef
def GetMatches(base: string): list<string>
def GetMatches(base: string, add_base: bool): list<string>
return getbufinfo()
->filter( (_, bf) => bf.listed )
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
->flattennew()
->sort()
->uniq()
->map( (_, v) => GetMatch(base, v, true) )
->filter( (_, i) => i.len != 0 )
->map( (_, v) => GetMatch(base, v, add_base) )
->filter( (_, i) => i.len > 3 )
->sort( (x, y) => y.len - x.len )
->map( (_, i) => i.val )
enddef
@@ -38,25 +39,13 @@ def LineSuffixCompl(findstart: bool, base: string): any
if findstart
return 0
endif
return GetMatches(base)
return GetMatches(base, true)
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) )
->filter( (_, v) => GetMatch(base, v, v:false) )
->sort( (x, y) => y[0] - x[0] )
->map( (_, v) => v[1] )
complete(col('.'), lines)
return ''
def DoLSCmpl()
GetMatches(getline('.'), false)->complete(col('.'))
enddef
# inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
set completefunc=LineSuffixCompl