Implement saving metadata to file

This commit is contained in:
Ivan Tishchenko 2015-01-04 00:24:32 +03:00
parent 2d0616343d
commit 6cafc97c9c

View File

@ -1930,10 +1930,16 @@ endfunction "}}}
" TAGS functions {{{ " TAGS functions {{{
let s:TAGS_METADATA_FILE_NAME = '.tags'
" Tags metadata in-memory format: " Tags metadata in-memory format:
" metadata := [ entry, ... ] " metadata := [ entry, ... ]
" entry := { 'tagname':..., 'pagename':..., 'lineno':..., 'link':... } " entry := { 'tagname':..., 'pagename':..., 'lineno':..., 'link':... }
" Tags metadata in-file format:
" * entry per line,
" * entry fields go in the same order as defined above, separated with TAB (\t)
" vimwiki#base#update_tags " vimwiki#base#update_tags
" Update tags metadata. " Update tags metadata.
" a:full_rebuild == 1: re-scan entire wiki " a:full_rebuild == 1: re-scan entire wiki
@ -2046,12 +2052,23 @@ endfunction " }}}
" vimwiki#base#merge_tags " vimwiki#base#merge_tags
" Merges two tags metadata objects into (new) one. " Merges two tags metadata objects into (new) one.
function! vimwiki#base#merge_tags(metadata1, metadata2) "{{{ function! vimwiki#base#merge_tags(metadata1, metadata2) "{{{
return [] return a:metadata1 + a:metadata2
endfunction " }}} endfunction " }}}
" vimwiki#base#write_tags_metadata " vimwiki#base#write_tags_metadata
" Saves metadata object into a file. Throws exceptions in case of problems. " Saves metadata object into a file. Throws exceptions in case of problems.
function! vimwiki#base#write_tags_metadata(metadata) "{{{ function! vimwiki#base#write_tags_metadata(metadata) "{{{
let metadata_path = VimwikiGet('path') . '/' . s:TAGS_METADATA_FILE_NAME
let entries = []
for entry in a:metadata
call add(entries,
\ entry.tagname . "\t"
\ . entry.pagename . "\t"
\ . entry.lineno . "\t"
\ . entry.link
\)
endfor
call writefile(entries, metadata_path)
endfunction " }}} endfunction " }}}
" }}} " }}}