Remove add_base and add doc

This commit is contained in:
2025-09-13 07:49:47 -04:00
parent a91696be7f
commit 7b8f3f7a5e
2 changed files with 33 additions and 15 deletions

21
lc.vim
View File

@@ -22,26 +22,23 @@ enddef
# echo GetLongestSuffix("hello world foo bar blah", "foo world")->assert_equal("o world")
# echo v:errors
def GetMatch(base: string, line: string, add_base: bool): Item
def GetMatch(base: string, line: string): Item
const s = GetLongestSuffix(line, base)
const idx = stridx(line, s)
const slen = strlen(s)
const m = strpart(line, idx + slen)
if add_base
return Item.new(slen, base .. m)
endif
return Item.new(slen, m)
return Item.new(slen, base .. m)
enddef
def GetMatches(base: string, add_base: bool): list<string>
def GetMatches(base: string): list<string>
return getbufinfo()
->filter( (_, bf) => bf.listed )
->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
->flattennew()
->sort()
->uniq()
->map( (_, v) => GetMatch(base, v, add_base) )
->filter( (_, m) => m.len > 3 )
->map( (_, v) => GetMatch(base, v) )
->filter( (_, m) => m.len > 2 )
->sort( (x, y) => y.len - x.len )
->map( (_, m) => m.val )
enddef
@@ -50,13 +47,9 @@ def LineSuffixCompl(findstart: bool, base: string): any
if findstart
return 0
endif
return GetMatches(base, true)
return GetMatches(base)
enddef
def DoLSCmpl()
GetMatches(getline('.'), false)->complete(col('.'))
enddef
inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
inoremap <C-X><C-L> <ScriptCmd>GetMatches(getline('.'))->complete(1)<CR>
set completefunc=LineSuffixCompl