commit f4c983b6b53327e9ab06f009007e680e7eb66cad
parent 3b5537f15aecbdf7ea66611e7d58b6aea96309ca
Author: Tinmarino <tinmarino@gmail.com>
Date: Sun, 17 May 2020 13:14:08 -0400
Feature: VimwikiGenerateLink take pattern optional argument
Issue #803
Diffstat:
3 files changed, 24 insertions(+), 8 deletions(-)
diff --git 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
@@ -889,8 +889,10 @@ Vimwiki file.
Commands are mapped to <A-Left> and <A-Right> 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
@@ -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, <f-args>)
command! -buffer -nargs=0 VimwikiBacklinks call vimwiki#base#backlinks()
command! -buffer -nargs=0 VWB call vimwiki#base#backlinks()