Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
35 changes: 35 additions & 0 deletions autoload/wiki/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,41 @@ function! s:completer_zotero.complete(regex) dict abort " {{{2
\}")
endfunction

" }}}1
" {{{1 Tags

let s:completer_tags = {}

function! s:completer_tags.findstart(line) dict abort " {{{2
" To avoid picking up the tag-end marker, extract the tags regex up to
" the \ze. If we can't find \ze, try the whole pattern.
let l:idx = stridx(g:wiki_tags_format_pattern, '\ze')
let l:pat = l:idx >= 0 ? strpart(g:wiki_tags_format_pattern, 0, l:idx) :
\ g:wiki_tags_format_pattern

"Match the last tag-start on the line
let l:start = 0
while 1
let l:mp = match(a:line, l:pat, l:start)
if l:mp > 0
let l:start = l:mp
else
break
endif
endwhile
return l:start > 0 ? l:start : -1

endfunction

function! s:completer_tags.complete(regex) dict abort " {{{2
let l:cands = keys(wiki#tags#get_all())
call filter(l:cands, 'stridx(v:val, a:regex) >= 0')
return map(sort(l:cands), "{
\ 'word': v:val,
\ 'kind': '[tag]'
\}")
endfunction

" }}}1

"
Expand Down
10 changes: 7 additions & 3 deletions doc/wiki.txt
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ OPTIONS *wiki-config-options*
Default: >
let g:wiki_tags_format_pattern = '\v%(^|\s):\zs[^: ]+\ze:'

Tag autocomplete (|wiki-completion|) uses the pattern up to '\ze' to detect
the start of an incomplete tag.

*g:wiki_tags_scan_num_lines*
A number of lines to read from the top of a page when scanning tags. To scan
lines from the bottom, use a negative number, e.g. >
Expand Down Expand Up @@ -1146,9 +1149,10 @@ The `[<attrlist>]` will be recognized by wiki.vim as the link text.
==============================================================================
COMPLETION *wiki-completion*

This plugin provides an |omni-complete| function that completes internal link
targets, including anchors. This should work both for markdown and wiki
style links (see |wiki-link|).
This plugin provides an |omni-complete| function that completes tags and
internal link targets, including anchors. Link completion should work both for
markdown and wiki style links (see |wiki-link|). Tag completion uses
|g:wiki_tags_format_pattern| to detect the start of an incomplete tag.

------------------------------------------------------------------------------
AUTOCOMPLETE *wiki-completion-auto*
Expand Down
2 changes: 1 addition & 1 deletion test/wiki-basic/tagged.wiki
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Intro
:tagged:
:tagged: :tagged2: :tagged3:

This is a wiki.