diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 420760c..07a99e4 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1945,21 +1945,29 @@ 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' + 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) + " Load metadata file + let metadata = vimwiki#base#load_tags_metadata() + " Drop old tags + let metadata = vimwiki#base#remove_page_from_tags(metadata, page_name) + " Merge in the new ones + 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 - " - let page_name = expand('%:t:r') - " Collect tags in current file - let tags = vimwiki#base#scan_tags(getline(1, '$'), page_name) - " Load metadata file - let metadata = vimwiki#base#load_tags_metadata() - " Drop old tags - let metadata = vimwiki#base#remove_page_from_tags(metadata, page_name) - " Merge in the new ones - let metadata = vimwiki#base#merge_tags(metadata, tags) - " Save - call vimwiki#base#write_tags_metadata(metadata) endfunction " }}} " vimwiki#base#scan_tags diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 39a4419..8df4a06 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -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* diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 313358b..3dc128f 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -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 {{{