Implement :VimwikiRebuildTags to rebuild metadata for all pages in current wiki

This commit is contained in:
Ivan Tishchenko 2015-01-06 22:30:28 +03:00
parent 4f639cebee
commit df91772d7e
3 changed files with 29 additions and 14 deletions

View File

@ -1945,10 +1945,8 @@ let s:TAGS_METADATA_FILE_NAME = '.tags'
" a:full_rebuild == 1: re-scan entire wiki
" a:full_rebuild == 0: only re-scan current page
function! vimwiki#base#update_tags(full_rebuild) "{{{
if a:full_rebuild
throw 'vimwiki#base#update_tags1: full rebuild not supported yet'
endif
"
if !a:full_rebuild
" Updating for one page (current)
let page_name = expand('%:t:r')
" Collect tags in current file
let tags = vimwiki#base#scan_tags(getline(1, '$'), page_name)
@ -1960,6 +1958,16 @@ function! vimwiki#base#update_tags(full_rebuild) "{{{
let metadata = vimwiki#base#merge_tags(metadata, tags)
" Save
call vimwiki#base#write_tags_metadata(metadata)
else " full rebuild
let files = s:find_files(g:vimwiki_current_idx, 0)
let metadata = []
for file in files
let page_name = fnamemodify(file, ':t:r')
let tags = vimwiki#base#scan_tags(readfile(file), page_name)
let metadata = vimwiki#base#merge_tags(metadata, tags)
endfor
call vimwiki#base#write_tags_metadata(metadata)
endif
endfunction " }}}
" vimwiki#base#scan_tags

View File

@ -704,6 +704,10 @@ il A single list item.
files are reachable from the index file. Errors are shown in the quickfix
window.
*:VimwikiRebuildTags*
Iterates over all files in a current wiki and rebuilds tags metadata (to
enable tags related commands).
==============================================================================
5. Wiki syntax *vimwiki-syntax*

View File

@ -302,6 +302,9 @@ command! -buffer VimwikiTableMoveColumnRight call vimwiki#tbl#move_column_right(
command! -buffer VimwikiDiaryNextDay call vimwiki#diary#goto_next_day()
command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day()
" tags commands
command! -buffer VimwikiRebuildTags call vimwiki#base#update_tags(1)
" COMMANDS }}}
" KEYBINDINGS {{{