diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index badadf4..5408655 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -381,13 +381,22 @@ function! vimwiki#base#get_globlinks_escaped(...) abort endfunction -function! vimwiki#base#generate_links(create) abort +" Optional pattern argument +function! vimwiki#base#generate_links(create, ...) abort + " Get pattern if present + " Globlal to script to be passed to closure + if a:0 + let s:pattern = a:1 + else + let s:pattern = '' + endif + " Define link generator closure let GeneratorLinks = copy(l:) function! GeneratorLinks.f() abort let lines = [] - let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0) + let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0, s:pattern) call sort(links) let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' ' @@ -478,7 +487,8 @@ endfunction " Returns: a list containing all files of the given wiki as absolute file path. " If the given wiki number is negative, the diary of the current wiki is used " If the second argument is not zero, only directories are found -function! vimwiki#base#find_files(wiki_nr, directories_only) abort +" If third argument: pattern to search for +function! vimwiki#base#find_files(wiki_nr, directories_only, ...) abort let wiki_nr = a:wiki_nr if wiki_nr >= 0 let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr) @@ -492,10 +502,13 @@ function! vimwiki#base#find_files(wiki_nr, directories_only) abort else let ext = vimwiki#vars#get_wikilocal('ext', wiki_nr) endif + " If pattern is given, use it " if current wiki is temporary -- was added by an arbitrary wiki file then do " not search wiki files in subdirectories. Or it would hang the system if " wiki file was created in $HOME or C:/ dirs. - if vimwiki#vars#get_wikilocal('is_temporary_wiki', wiki_nr) + if a:0 && a:1 != '' + let pattern = a:1 + elseif vimwiki#vars#get_wikilocal('is_temporary_wiki', wiki_nr) let pattern = '*'.ext else let pattern = '**/*'.ext @@ -516,8 +529,8 @@ endfunction " files in the given wiki. " If the given wiki number is negative, the diary of the current wiki is used. " If also_absolute_links is nonzero, also return links of the form /file -function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links) abort - let files = vimwiki#base#find_files(a:wiki_nr, 0) +function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links, pattern) abort + let files = vimwiki#base#find_files(a:wiki_nr, 0, a:pattern) if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr') let cwd = vimwiki#path#wikify_path(expand('%:p:h')) elseif a:wiki_nr < 0 diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index dfe9e6f..796d234 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -889,8 +889,10 @@ Vimwiki file. Commands are mapped to and respectively. -*:VimwikiGenerateLinks* +*:VimwikiGenerateLinks* [pattern] Insert the links of all available wiki files into the current buffer. + If an optional 'pattern' is given as argument, the files will be searched + in the wiki root folder according to the 'pattern' as |globpath| *:VimwikiDiaryGenerateLinks* Delete old, insert new diary section into diary index file. @@ -3623,6 +3625,7 @@ Fixed:~ rendered correctly. * Issue #835: Pressing enter on the dash of a markdown list causes an error. * Issue #876: E684: list index out of range: 0, when creating a link containing a `.`. + * Issue #803: `:VimwikiGenerateLinks` for subdirectory only 2.4 (2019-03-24)~ diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index b1bd96c..2837fa1 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -253,7 +253,7 @@ command! -buffer -nargs=? VimwikiNormalizeLink call vimwiki#base#normalize_link( command! -buffer VimwikiTabnewLink call vimwiki#base#follow_link('tab', 0, 1) -command! -buffer VimwikiGenerateLinks call vimwiki#base#generate_links(1) +command! -buffer -nargs=? VimwikiGenerateLinks call vimwiki#base#generate_links(1, ) command! -buffer -nargs=0 VimwikiBacklinks call vimwiki#base#backlinks() command! -buffer -nargs=0 VWB call vimwiki#base#backlinks()