Make generation functions compatible with older vims.
PR #634, PR #635, and PR #636 introduced new features that broke compatibility with older version of Vim. This modifies those changes to ensure compatibility. Closes #781. Removes usage of funcref(), closure. Fixes filter() call. Made globpath calls not use the list argument. Unlet a variable that is reused (sticky type checking) v7.4.1989 modified filter() to accept a Funcref v7.4.2120 Added function "closure" argument v7.4.2137 add funcref()
This commit is contained in:
parent
c8bb658360
commit
460fcb692e
@ -380,7 +380,8 @@ endfunction
|
||||
|
||||
function! vimwiki#base#generate_links(create)
|
||||
|
||||
function! Generator() closure
|
||||
let GeneratorLinks = copy(l:)
|
||||
function! GeneratorLinks.f()
|
||||
let lines = []
|
||||
|
||||
let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0)
|
||||
@ -413,7 +414,7 @@ function! vimwiki#base#generate_links(create)
|
||||
let links_rx = '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)'
|
||||
|
||||
call vimwiki#base#update_listing_in_buffer(
|
||||
\ funcref('Generator'),
|
||||
\ GeneratorLinks,
|
||||
\ vimwiki#vars#get_global('links_header'),
|
||||
\ links_rx,
|
||||
\ line('$')+1,
|
||||
@ -489,17 +490,15 @@ function! vimwiki#base#find_files(wiki_nr, directories_only)
|
||||
else
|
||||
let pattern = '**/*'.ext
|
||||
endif
|
||||
let files = globpath(root_directory, pattern, 0, 1)
|
||||
let files = split(globpath(root_directory, pattern))
|
||||
|
||||
" filter excluded files before returning
|
||||
function! ExcludeFiles(idx, val) closure
|
||||
for pattern in vimwiki#vars#get_wikilocal('exclude_files')
|
||||
if index(globpath(root_directory, pattern, 0, 1), a:val) != -1
|
||||
return 0
|
||||
endif
|
||||
let efiles = split(globpath(root_directory, pattern))
|
||||
let files = filter(files, 'index(efiles, v:val) == -1')
|
||||
endfor
|
||||
return 1
|
||||
endfunction
|
||||
return filter(files, funcref('ExcludeFiles'))
|
||||
|
||||
return files
|
||||
endfunction
|
||||
|
||||
|
||||
@ -1209,7 +1208,7 @@ function! vimwiki#base#update_listing_in_buffer(Generator, start_header,
|
||||
let lines_diff += 1
|
||||
endfor
|
||||
endif
|
||||
for string in a:Generator()
|
||||
for string in a:Generator.f()
|
||||
keepjumps call append(start_lnum - 1, string)
|
||||
let start_lnum += 1
|
||||
let lines_diff += 1
|
||||
@ -1999,15 +1998,18 @@ function! vimwiki#base#table_of_contents(create)
|
||||
endif
|
||||
endif
|
||||
|
||||
function! Generator() closure
|
||||
" use a dictionary function for closure like capability
|
||||
" copy all local variables into dict (add a: if arguments are needed)
|
||||
let GeneratorTOC = copy(l:)
|
||||
function! GeneratorTOC.f()
|
||||
let numbering = vimwiki#vars#get_global('html_header_numbering')
|
||||
let headers_levels = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]]
|
||||
let complete_header_infos = []
|
||||
for header in headers
|
||||
for header in self.headers
|
||||
let h_text = header[2]
|
||||
let h_level = header[1]
|
||||
" don't include the TOC's header itself
|
||||
if h_text ==# toc_header_text
|
||||
if h_text ==# self.toc_header_text
|
||||
continue
|
||||
endif
|
||||
let headers_levels[h_level-1] = [h_text, headers_levels[h_level-1][1]+1]
|
||||
@ -2050,7 +2052,7 @@ function! vimwiki#base#table_of_contents(create)
|
||||
let links_rx = '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)'
|
||||
|
||||
call vimwiki#base#update_listing_in_buffer(
|
||||
\ funcref('Generator'),
|
||||
\ GeneratorTOC,
|
||||
\ toc_header_text,
|
||||
\ links_rx,
|
||||
\ 1,
|
||||
|
@ -312,7 +312,8 @@ endfunction
|
||||
|
||||
function! vimwiki#diary#generate_diary_section()
|
||||
|
||||
function! Generator() closure
|
||||
let GeneratorDiary = copy(l:)
|
||||
function! GeneratorDiary.f()
|
||||
let lines = []
|
||||
|
||||
let links_with_captions = s:read_captions(s:get_diary_files())
|
||||
@ -392,7 +393,7 @@ function! vimwiki#diary#generate_diary_section()
|
||||
\ '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)'
|
||||
|
||||
call vimwiki#base#update_listing_in_buffer(
|
||||
\ funcref('Generator'),
|
||||
\ GeneratorDiary,
|
||||
\ vimwiki#vars#get_wikilocal('diary_header'),
|
||||
\ content_rx,
|
||||
\ 1,
|
||||
|
@ -303,8 +303,11 @@ function! vimwiki#tags#generate_tags(create, ...) abort
|
||||
let specific_tags = a:000
|
||||
let header_level = vimwiki#vars#get_global('tags_header_level')
|
||||
|
||||
function! Generator() closure
|
||||
let need_all_tags = empty(specific_tags)
|
||||
" use a dictionary function for closure like capability
|
||||
" copy all local variables into dict (add a: if arguments are needed)
|
||||
let GeneratorTags = copy(l:)
|
||||
function! GeneratorTags.f()
|
||||
let need_all_tags = empty(self.specific_tags)
|
||||
let metadata = s:load_tags_metadata()
|
||||
|
||||
" make a dictionary { tag_name: [tag_links, ...] }
|
||||
@ -317,17 +320,18 @@ function! vimwiki#tags#generate_tags(create, ...) abort
|
||||
let tags_entries[entry.tagname] = [entry.link]
|
||||
endif
|
||||
endfor
|
||||
unlet entry " needed for older vims with sticky type checking since name is reused
|
||||
endfor
|
||||
|
||||
let lines = []
|
||||
let bullet = repeat(' ', vimwiki#lst#get_list_margin()).vimwiki#lst#default_symbol().' '
|
||||
for tagname in sort(keys(tags_entries))
|
||||
if need_all_tags || index(specific_tags, tagname) != -1
|
||||
if need_all_tags || index(self.specific_tags, tagname) != -1
|
||||
if len(lines) > 0
|
||||
call add(lines, '')
|
||||
endif
|
||||
|
||||
let tag_tpl = printf('rxH%d_Template', header_level + 1)
|
||||
let tag_tpl = printf('rxH%d_Template', self.header_level + 1)
|
||||
call add(lines, s:safesubstitute(vimwiki#vars#get_syntaxlocal(tag_tpl), '__Header__', tagname, ''))
|
||||
|
||||
if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
|
||||
@ -363,7 +367,7 @@ function! vimwiki#tags#generate_tags(create, ...) abort
|
||||
\ '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)'
|
||||
|
||||
call vimwiki#base#update_listing_in_buffer(
|
||||
\ funcref('Generator'),
|
||||
\ GeneratorTags,
|
||||
\ vimwiki#vars#get_global('tags_header'),
|
||||
\ links_rx,
|
||||
\ line('$')+1,
|
||||
|
Loading…
Reference in New Issue
Block a user