Implement :VimwikiRebuildTags to rebuild metadata for all pages in current wiki
This commit is contained in:
parent
4f639cebee
commit
df91772d7e
@ -1945,21 +1945,29 @@ let s:TAGS_METADATA_FILE_NAME = '.tags'
|
|||||||
" a:full_rebuild == 1: re-scan entire wiki
|
" a:full_rebuild == 1: re-scan entire wiki
|
||||||
" a:full_rebuild == 0: only re-scan current page
|
" a:full_rebuild == 0: only re-scan current page
|
||||||
function! vimwiki#base#update_tags(full_rebuild) "{{{
|
function! vimwiki#base#update_tags(full_rebuild) "{{{
|
||||||
if a:full_rebuild
|
if !a:full_rebuild
|
||||||
throw 'vimwiki#base#update_tags1: full rebuild not supported yet'
|
" 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
|
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 " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" vimwiki#base#scan_tags
|
" vimwiki#base#scan_tags
|
||||||
|
@ -704,6 +704,10 @@ il A single list item.
|
|||||||
files are reachable from the index file. Errors are shown in the quickfix
|
files are reachable from the index file. Errors are shown in the quickfix
|
||||||
window.
|
window.
|
||||||
|
|
||||||
|
*:VimwikiRebuildTags*
|
||||||
|
Iterates over all files in a current wiki and rebuilds tags metadata (to
|
||||||
|
enable tags related commands).
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
5. Wiki syntax *vimwiki-syntax*
|
5. Wiki syntax *vimwiki-syntax*
|
||||||
|
|
||||||
|
@ -302,6 +302,9 @@ command! -buffer VimwikiTableMoveColumnRight call vimwiki#tbl#move_column_right(
|
|||||||
command! -buffer VimwikiDiaryNextDay call vimwiki#diary#goto_next_day()
|
command! -buffer VimwikiDiaryNextDay call vimwiki#diary#goto_next_day()
|
||||||
command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day()
|
command! -buffer VimwikiDiaryPrevDay call vimwiki#diary#goto_prev_day()
|
||||||
|
|
||||||
|
" tags commands
|
||||||
|
command! -buffer VimwikiRebuildTags call vimwiki#base#update_tags(1)
|
||||||
|
|
||||||
" COMMANDS }}}
|
" COMMANDS }}}
|
||||||
|
|
||||||
" KEYBINDINGS {{{
|
" KEYBINDINGS {{{
|
||||||
|
Loading…
Reference in New Issue
Block a user