Support for omni completion of tags

This commit is contained in:
Ivan Tishchenko 2015-01-05 01:29:42 +03:00
parent c7436a44cf
commit a01290160c
2 changed files with 27 additions and 1 deletions

View File

@ -2087,6 +2087,16 @@ function! vimwiki#base#write_tags_metadata(metadata) "{{{
call writefile(entries, metadata_path)
endfunction " }}}
" vimwiki#base#get_tags
" Returns list of unique tags found in metadata
function! vimwiki#base#get_tags(metadata) "{{{
let tags = {}
for entry in a:metadata
let tags[entry.tagname] = 1
endfor
return keys(tags)
endfunction " }}}
" }}}
" Command completion functions {{{

View File

@ -49,9 +49,25 @@ function! Complete_wikifiles(findstart, base)
return startofinlinelink
endif
endif
let startoftag = match(line, ':\zs[^:[:space:]]*$')
if startoftag != -1
return startoftag
endif
return -1
else
if a:base !~ '#'
" Completion works for wikilinks/anchors, and for tags. So first we have
" to find out what we're about to complete.
let column = col('.')
let line = getline('.')[:(column - len(a:base))]
let char_before_start = line[-1:-1]
if char_before_start == ':'
" Tags completion
let metadata = vimwiki#base#load_tags_metadata()
let tags = vimwiki#base#get_tags(metadata)
call filter(tags,
\ "v:val[:" . (len(a:base)-1) . "] == '" . substitute(a:base, "'", "''", '') . "'" )
return tags
elseif a:base !~ '#'
" we look for wiki files
if a:base =~# '^wiki\d:'