Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

Split complete function #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 34 additions & 26 deletions autoload/minisnip.vim
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ function! s:SelectPlaceholder() abort
let @s = l:old_s
endfunction

function! minisnip#complete() abort
" Locate the start of the word
let l:line = getline('.')
let l:start = col('.') - 1
while l:start > 0 && l:line[l:start - 1] =~? '\a'
let l:start -= 1
endwhile
let l:base = l:line[l:start : col('.')-1]
if l:base is# ' '
let l:base = ''
function! minisnip#completefunc(findstart, base) abort
if a:findstart
" Locate the start of the word
let l:line = getline('.')
let l:start = col('.') - 1
while l:start > 0 && l:line[l:start - 1] =~? '\a'
let l:start -= 1
endwhile

return l:start
endif

" Load all snippets that match.
Expand All @@ -152,25 +152,33 @@ function! minisnip#complete() abort
if l:name !~? '^' . l:base
Copy link
Owner

@joereynolds joereynolds Dec 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a:base?

continue
endif
let l:all += [[l:name, readfile(l:path)]]

let l:content = readfile(l:path)
call add(l:all, {
\ 'icase': 1,
\ 'word': l:name,
\ 'abbr': l:name,
\ 'menu': l:content[0],
\ 'info': join(l:content, "\n"),
\ })
endfor
endfor
call sort(l:all, {i1, i2 -> l:i1[0] == l:i2[0] ? 0 : l:i1[0] > l:i2[0] ? 1 : -1})

" Format how complete() expects it.
let l:res = []
for l:m in l:all
call add(l:res, {
\ 'icase': 1,
\ 'word': l:m[0],
\ 'abbr': l:m[0],
\ 'menu': l:m[1][0],
\ 'info': join(l:m[1], "\n"),
\ })
endfor
call sort(l:all, {i1, i2 -> i1.word == i2.word ? 0 : i1.word > i2.word ? 1 : -1})

return l:all
endfunction

function! minisnip#complete() abort
let l:line = getline('.')
let l:start = minisnip#completefunc(1, '')
let l:base = l:line[l:start : col('.')-1]
if l:base is# ' '
let l:base = ''
endif

let l:all = minisnip#completefunc(0, l:base)

call complete(l:start + 1, l:res)
return ''
call complete(l:start + 1, l:all)
endfunction

" Get the path separator for this platform.
Expand Down