From e3203d36d405a8ffff5cbf858b7c246c5de07a5e Mon Sep 17 00:00:00 2001 From: Daniel Ashbrook Date: Sat, 24 Jul 2021 16:48:37 +0200 Subject: [PATCH 1/3] Add tag completion --- autoload/wiki/complete.vim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/autoload/wiki/complete.vim b/autoload/wiki/complete.vim index 88e20a28..8cb83972 100644 --- a/autoload/wiki/complete.vim +++ b/autoload/wiki/complete.vim @@ -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 " From 92cad48718650e862b31e2df33e076d85dd4ec46 Mon Sep 17 00:00:00 2001 From: Daniel Ashbrook Date: Sun, 25 Jul 2021 11:30:07 +0200 Subject: [PATCH 2/3] Add tag completion documentation --- doc/wiki.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/wiki.txt b/doc/wiki.txt index f75a1069..fc8093c1 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -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. > @@ -1146,9 +1149,10 @@ The `[]` 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* From 8ba9d6446a6492fcfce14624751d24d6222d81d4 Mon Sep 17 00:00:00 2001 From: Daniel Ashbrook Date: Sat, 31 Jul 2021 19:39:21 +0200 Subject: [PATCH 3/3] Add tags for basic completion testing --- test/wiki-basic/tagged.wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/wiki-basic/tagged.wiki b/test/wiki-basic/tagged.wiki index 3618688c..2aacd52c 100644 --- a/test/wiki-basic/tagged.wiki +++ b/test/wiki-basic/tagged.wiki @@ -1,5 +1,5 @@ # Intro -:tagged: +:tagged: :tagged2: :tagged3: This is a wiki.