Remove add_base and add doc
This commit is contained in:
		
							
								
								
									
										27
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								README.md
									
									
									
									
									
								
							@@ -1 +1,26 @@
 | 
				
			|||||||
# Smart Whole line completion
 | 
					# Line Suffix completion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Like vim's [whole line completion][0], but works even if the start of the line
 | 
				
			||||||
 | 
					does not fully match.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```javascript
 | 
				
			||||||
 | 
					var foo = SomeBigName(arg1, arg2, arg3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# now when creating a similar variable, the mapping completes rest of the line.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var bar = Some<C-X><C-L>
 | 
				
			||||||
 | 
					var bar = SomeBigName(arg1, arg2, arg3)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## TODO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- [ ] Convert to proper vim plugin. For now, `source /path/to/lc.vim`
 | 
				
			||||||
 | 
					- [ ] Use <Plug> and add option to disable mapping by default
 | 
				
			||||||
 | 
					- [ ] Make the min length of suffix configurable. Now 2
 | 
				
			||||||
 | 
					- [ ] Add tests for GetLongestSuffix
 | 
				
			||||||
 | 
					- [ ] Use better algorithm for GetLongestSuffix
 | 
				
			||||||
 | 
					- [ ] Add doc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[0]: https://vimhelp.org/insert.txt.html#compl-whole-line
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								lc.vim
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								lc.vim
									
									
									
									
									
								
							@@ -22,26 +22,23 @@ enddef
 | 
				
			|||||||
# echo GetLongestSuffix("hello world foo bar blah", "foo world")->assert_equal("o world")
 | 
					# echo GetLongestSuffix("hello world foo bar blah", "foo world")->assert_equal("o world")
 | 
				
			||||||
# echo v:errors
 | 
					# 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 s = GetLongestSuffix(line, base)
 | 
				
			||||||
    const idx = stridx(line, s)
 | 
					    const idx = stridx(line, s)
 | 
				
			||||||
    const slen = strlen(s)
 | 
					    const slen = strlen(s)
 | 
				
			||||||
    const  m = strpart(line, idx + slen)
 | 
					    const  m = strpart(line, idx + slen)
 | 
				
			||||||
    if add_base
 | 
					    return Item.new(slen, base .. m)
 | 
				
			||||||
        return Item.new(slen, base .. m)
 | 
					 | 
				
			||||||
    endif
 | 
					 | 
				
			||||||
    return Item.new(slen, m)
 | 
					 | 
				
			||||||
enddef
 | 
					enddef
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def GetMatches(base: string, add_base: bool): list<string>
 | 
					def GetMatches(base: string): list<string>
 | 
				
			||||||
    return getbufinfo()
 | 
					    return getbufinfo()
 | 
				
			||||||
        ->filter( (_, bf) => bf.listed )
 | 
					        ->filter( (_, bf) => bf.listed )
 | 
				
			||||||
        ->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
 | 
					        ->map( (_, buf) => getbufline(buf["bufnr"], 1, "$"))
 | 
				
			||||||
        ->flattennew()
 | 
					        ->flattennew()
 | 
				
			||||||
        ->sort()
 | 
					        ->sort()
 | 
				
			||||||
        ->uniq()
 | 
					        ->uniq()
 | 
				
			||||||
        ->map( (_, v) => GetMatch(base, v, add_base) )
 | 
					        ->map( (_, v) => GetMatch(base, v) )
 | 
				
			||||||
        ->filter( (_, m) => m.len > 3 )
 | 
					        ->filter( (_, m) => m.len > 2 )
 | 
				
			||||||
        ->sort( (x, y) => y.len - x.len )
 | 
					        ->sort( (x, y) => y.len - x.len )
 | 
				
			||||||
        ->map( (_, m) => m.val )
 | 
					        ->map( (_, m) => m.val )
 | 
				
			||||||
enddef
 | 
					enddef
 | 
				
			||||||
@@ -50,13 +47,9 @@ def LineSuffixCompl(findstart: bool, base: string): any
 | 
				
			|||||||
    if findstart
 | 
					    if findstart
 | 
				
			||||||
        return 0
 | 
					        return 0
 | 
				
			||||||
    endif
 | 
					    endif
 | 
				
			||||||
    return GetMatches(base, true)
 | 
					    return GetMatches(base)
 | 
				
			||||||
enddef
 | 
					enddef
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def DoLSCmpl()
 | 
					inoremap <C-X><C-L> <ScriptCmd>GetMatches(getline('.'))->complete(1)<CR>
 | 
				
			||||||
    GetMatches(getline('.'), false)->complete(col('.'))
 | 
					 | 
				
			||||||
enddef
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
inoremap <C-X><C-L> <C-R>=<SID>DoLSCmpl()<CR>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
set completefunc=LineSuffixCompl
 | 
					set completefunc=LineSuffixCompl
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user