From e44b188a497576393fab62d021e9f87c3ffe3a85 Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Tue, 6 Jan 2015 23:13:28 +0300 Subject: [PATCH] :VimwikiGenerateTags --- autoload/vimwiki/base.vim | 33 +++++++++++++++++++++++++++++++++ doc/vimwiki.txt | 5 +++++ ftplugin/vimwiki.vim | 2 ++ 3 files changed, 40 insertions(+) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index f5c792a..b368042 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -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 {{{ diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index a1db1b3..70bf723 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -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* diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index aa8dd17..434ed52 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -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 /::/ +command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_tags + \ VimwikiGenerateTags call vimwiki#base#generate_tags() " COMMANDS }}}