Simplify a function call
This commit is contained in:
parent
d28b615286
commit
b808dcfdc1
@ -32,7 +32,7 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
|
|||||||
" Collect tags in current file
|
" Collect tags in current file
|
||||||
let tags = s:scan_tags(getline(1, '$'), page_name)
|
let tags = s:scan_tags(getline(1, '$'), page_name)
|
||||||
" Load metadata file
|
" Load metadata file
|
||||||
let metadata = vimwiki#tags#load_tags_metadata()
|
let metadata = s:load_tags_metadata()
|
||||||
" Drop old tags
|
" Drop old tags
|
||||||
let metadata = s:remove_page_from_tags(metadata, page_name)
|
let metadata = s:remove_page_from_tags(metadata, page_name)
|
||||||
" Merge in the new ones
|
" Merge in the new ones
|
||||||
@ -43,7 +43,7 @@ function! vimwiki#tags#update_tags(full_rebuild, all_files) "{{{
|
|||||||
let files = vimwiki#base#find_files(g:vimwiki_current_idx, 0)
|
let files = vimwiki#base#find_files(g:vimwiki_current_idx, 0)
|
||||||
let tags_file_last_modification =
|
let tags_file_last_modification =
|
||||||
\ getftime(vimwiki#tags#metadata_file_path())
|
\ getftime(vimwiki#tags#metadata_file_path())
|
||||||
let metadata = vimwiki#tags#load_tags_metadata()
|
let metadata = s:load_tags_metadata()
|
||||||
for file in files
|
for file in files
|
||||||
if all_files || getftime(file) >= tags_file_last_modification
|
if all_files || getftime(file) >= tags_file_last_modification
|
||||||
let page_name = fnamemodify(file, ':t:r')
|
let page_name = fnamemodify(file, ':t:r')
|
||||||
@ -141,9 +141,9 @@ function! vimwiki#tags#metadata_file_path() abort "{{{
|
|||||||
return fnamemodify(VimwikiGet('path') . '/' . s:TAGS_METADATA_FILE_NAME, ':p')
|
return fnamemodify(VimwikiGet('path') . '/' . s:TAGS_METADATA_FILE_NAME, ':p')
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" vimwiki#tags#load_tags_metadata
|
" s:load_tags_metadata
|
||||||
" Loads tags metadata from file, returns a dictionary
|
" Loads tags metadata from file, returns a dictionary
|
||||||
function! vimwiki#tags#load_tags_metadata() abort "{{{
|
function! s:load_tags_metadata() abort "{{{
|
||||||
let metadata_path = vimwiki#tags#metadata_file_path()
|
let metadata_path = vimwiki#tags#metadata_file_path()
|
||||||
if !filereadable(metadata_path)
|
if !filereadable(metadata_path)
|
||||||
return {}
|
return {}
|
||||||
@ -239,10 +239,11 @@ function! s:write_tags_metadata(metadata) "{{{
|
|||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
" vimwiki#tags#get_tags
|
" vimwiki#tags#get_tags
|
||||||
" Returns list of unique tags found in metadata
|
" Returns list of unique tags found in the .tags file
|
||||||
function! vimwiki#tags#get_tags(metadata) "{{{
|
function! vimwiki#tags#get_tags() "{{{
|
||||||
|
let metadata = s:load_tags_metadata()
|
||||||
let tags = {}
|
let tags = {}
|
||||||
for entries in values(a:metadata)
|
for entries in values(metadata)
|
||||||
for entry in entries
|
for entry in entries
|
||||||
let tags[entry.tagname] = 1
|
let tags[entry.tagname] = 1
|
||||||
endfor
|
endfor
|
||||||
@ -258,7 +259,7 @@ function! vimwiki#tags#generate_tags(...) abort "{{{
|
|||||||
let need_all_tags = (a:0 == 0)
|
let need_all_tags = (a:0 == 0)
|
||||||
let specific_tags = a:000
|
let specific_tags = a:000
|
||||||
|
|
||||||
let metadata = vimwiki#tags#load_tags_metadata()
|
let metadata = s:load_tags_metadata()
|
||||||
|
|
||||||
call append(line('$'), [
|
call append(line('$'), [
|
||||||
\ '',
|
\ '',
|
||||||
@ -295,8 +296,7 @@ endfunction " }}}
|
|||||||
function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort " {{{
|
function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort " {{{
|
||||||
" We can safely ignore args if we use -custom=complete option, Vim engine
|
" We can safely ignore args if we use -custom=complete option, Vim engine
|
||||||
" will do the job of filtering.
|
" will do the job of filtering.
|
||||||
let metadata = vimwiki#tags#load_tags_metadata()
|
let taglist = vimwiki#tags#get_tags()
|
||||||
let taglist = vimwiki#tags#get_tags(metadata)
|
|
||||||
return join(taglist, "\n")
|
return join(taglist, "\n")
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
|
|
||||||
|
@ -67,8 +67,7 @@ function! Complete_wikifiles(findstart, base)
|
|||||||
return []
|
return []
|
||||||
elseif s:line_context == ':'
|
elseif s:line_context == ':'
|
||||||
" Tags completion
|
" Tags completion
|
||||||
let metadata = vimwiki#tags#load_tags_metadata()
|
let tags = vimwiki#tags#get_tags()
|
||||||
let tags = vimwiki#tags#get_tags(metadata)
|
|
||||||
if a:base != ''
|
if a:base != ''
|
||||||
call filter(tags,
|
call filter(tags,
|
||||||
\ "v:val[:" . (len(a:base)-1) . "] == '" . substitute(a:base, "'", "''", '') . "'" )
|
\ "v:val[:" . (len(a:base)-1) . "] == '" . substitute(a:base, "'", "''", '') . "'" )
|
||||||
|
Loading…
Reference in New Issue
Block a user