:VimwikiGenerateTags

This commit is contained in:
Ivan Tishchenko 2015-01-06 23:13:28 +03:00
parent a62bebceb2
commit e44b188a49
3 changed files with 40 additions and 0 deletions

View File

@ -2105,6 +2105,39 @@ function! vimwiki#base#get_tags(metadata) "{{{
return keys(tags)
endfunction " }}}
" vimwiki#base#generate_tags
" Similar to vimwiki#base#generate_links. In the current buffer, appends
" tags and references to all their instances. If no arguments (tags) are
" specified, outputs all tags.
function! vimwiki#base#generate_tags(...) abort "{{{
let need_all_tags = (a:0 == 0)
let specific_tags = a:000
let metadata = vimwiki#base#load_tags_metadata()
call append(line('$'), [
\ '',
\ substitute(g:vimwiki_rxH1_Template, '__Header__', 'Generated Tags', '') ])
call sort(metadata)
let bullet = repeat(' ', vimwiki#lst#get_list_margin()).
\ vimwiki#lst#default_symbol().' '
let current_tag = ''
for entry in metadata
if need_all_tags || index(specific_tags, entry.tagname) != -1
if entry.tagname != current_tag
let current_tag = entry.tagname
call append(line('$'), [
\ '',
\ substitute(g:vimwiki_rxH2_Template, '__Header__', entry.tagname, ''),
\ '' ])
endif
call append(line('$'), bullet . '[[' . entry.link . ']]')
endif
endfor
endfunction " }}}
" }}}
" Command completion functions {{{

View File

@ -712,6 +712,11 @@ il A single list item.
Searches over the pages in current wiki and finds all locations of a given
tag. Supports |cmdline-completion|.
*:VimwikiGenerateTags*
Similar to |:VimwikiGenerateLinks|. In the current buffer, appends tags
and references to all their instances. Supports |cmdline-completion|. If
no arguments (tags) are specified, outputs all tags.
==============================================================================
5. Wiki syntax *vimwiki-syntax*

View File

@ -306,6 +306,8 @@ command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day()
command! -buffer VimwikiRebuildTags call vimwiki#base#update_tags(1)
command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_tags
\ VimwikiSearchTags VimwikiSearch /:<args>:/
command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_tags
\ VimwikiGenerateTags call vimwiki#base#generate_tags(<f-args>)
" COMMANDS }}}