From 395cfec299f47244bc26022e433f4f3f8d861b4a Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Thu, 6 Nov 2014 23:52:26 +0300 Subject: [PATCH 1/4] Extract links list generation to an individual function --- autoload/vimwiki/base.vim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index ef07b06..888d23d 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -560,8 +560,8 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{ endif endfunction " }}} -" vimwiki#base#generate_links -function! vimwiki#base#generate_links() "{{{only get links from the current dir +" vimwiki#base#generate_globlinks +function! vimwiki#base#get_globlinks() abort "{{{only get links from the current dir " change to the directory of the current file let orig_pwd = getcwd() lcd! %:h @@ -571,6 +571,13 @@ function! vimwiki#base#generate_links() "{{{only get links from the current dir let globlinks = substitute(globlinks, '\'.VimwikiGet('ext').'\ze\n', '', 'g') " restore the original working directory exe 'lcd! '.orig_pwd + " return all links as a single newline-separated string + return globlinks +endfunction " }}} + +" vimwiki#base#generate_links +function! vimwiki#base#generate_links() "{{{only get links from the current dir + let globlinks = vimwiki#base#get_globlinks() " We don't want link to itself. XXX Why ??? " let cur_link = expand('%:t:r') From f7df798b25a3f8948a51d225df6b7aee0a1e0ddc Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Fri, 7 Nov 2014 00:02:37 +0300 Subject: [PATCH 2/4] Support autocompletion of link argument for VimwikiGoto command --- autoload/vimwiki/base.vim | 11 +++++++++++ ftplugin/vimwiki.vim | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 888d23d..07be114 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -1804,6 +1804,17 @@ endfunction "}}} " }}} +" Command completion functions {{{ + +" vimwiki#base#complete_links +function! vimwiki#base#complete_links(ArgLead, CmdLine, CursorPos) abort " {{{ + " We can safely ignore args if we use -custom=complete option, Vim engine + " will do the job of filtering. + return vimwiki#base#get_globlinks() +endfunction " }}} + +"}}} + " ------------------------------------------------------------------------- " Load syntax-specific Wiki functionality for s:syn in vimwiki#base#get_known_syntaxes() diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index a89a8a8..e79d8e0 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -283,7 +283,8 @@ exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep '. exe 'command! -buffer -nargs=* VWS lvimgrep '. \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') -command! -buffer -nargs=+ VimwikiGoto call vimwiki#base#goto() +command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links + \ VimwikiGoto call vimwiki#base#goto() " list commands From 6b9edefecc2f858bc5c55effb41f78373bb6ef44 Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Mon, 10 Nov 2014 23:04:06 +0300 Subject: [PATCH 3/4] Fixed misprint in comments; corrected completion to escape filenames properly; add documentation. --- autoload/vimwiki/base.vim | 18 +++++++++++++++++- doc/vimwiki.txt | 2 ++ ftplugin/vimwiki.vim | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 07be114..828f4a9 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -560,7 +560,7 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{ endif endfunction " }}} -" vimwiki#base#generate_globlinks +" vimwiki#base#get_globlinks function! vimwiki#base#get_globlinks() abort "{{{only get links from the current dir " change to the directory of the current file let orig_pwd = getcwd() @@ -575,6 +575,15 @@ function! vimwiki#base#get_globlinks() abort "{{{only get links from the current return globlinks endfunction " }}} +" vimwiki#base#get_globlinks_escaped +function! vimwiki#base#get_globlinks_escaped() abort "{{{only get links from the current dir + let globlinks = vimwiki#base#get_globlinks() + let lst = split(globlinks, '\n') + call map(lst, 'fnameescape(v:val)') + let globlinks = join(lst, "\n") + return globlinks +endfunction " }}} + " vimwiki#base#generate_links function! vimwiki#base#generate_links() "{{{only get links from the current dir let globlinks = vimwiki#base#get_globlinks() @@ -1813,6 +1822,13 @@ function! vimwiki#base#complete_links(ArgLead, CmdLine, CursorPos) abort " {{{ return vimwiki#base#get_globlinks() endfunction " }}} +" vimwiki#base#complete_links_escaped +function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort " {{{ + " We can safely ignore args if we use -custom=complete option, Vim engine + " will do the job of filtering. + return vimwiki#base#get_globlinks_escaped() +endfunction " }}} + "}}} " ------------------------------------------------------------------------- diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index f2efcec..442bed7 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -597,6 +597,8 @@ il A single list item. :VimwikiGoto HelloWorld < opens opens/creates HelloWorld wiki page. + Supports |cmdline-completion| for link name. + *:VimwikiDeleteLink* Delete the wiki page that you are in. diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index e79d8e0..2d4276c 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -283,7 +283,7 @@ exe 'command! -buffer -nargs=* VimwikiSearch lvimgrep '. exe 'command! -buffer -nargs=* VWS lvimgrep '. \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') -command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links +command! -buffer -nargs=+ -complete=custom,vimwiki#base#complete_links_escaped \ VimwikiGoto call vimwiki#base#goto() From f47f3c4e26d20f6638db007561dbcc1670ef48a1 Mon Sep 17 00:00:00 2001 From: Ivan Tishchenko Date: Tue, 11 Nov 2014 23:12:03 +0300 Subject: [PATCH 4/4] Removed unused functions; added a few more comments --- autoload/vimwiki/base.vim | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index 828f4a9..3b849ec 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -560,8 +560,8 @@ function! vimwiki#base#open_link(cmd, link, ...) "{{{ endif endfunction " }}} -" vimwiki#base#get_globlinks -function! vimwiki#base#get_globlinks() abort "{{{only get links from the current dir +" vimwiki#base#get_globlinks_escaped +function! vimwiki#base#get_globlinks_escaped() abort "{{{only get links from the current dir " change to the directory of the current file let orig_pwd = getcwd() lcd! %:h @@ -571,16 +571,13 @@ function! vimwiki#base#get_globlinks() abort "{{{only get links from the current let globlinks = substitute(globlinks, '\'.VimwikiGet('ext').'\ze\n', '', 'g') " restore the original working directory exe 'lcd! '.orig_pwd - " return all links as a single newline-separated string - return globlinks -endfunction " }}} - -" vimwiki#base#get_globlinks_escaped -function! vimwiki#base#get_globlinks_escaped() abort "{{{only get links from the current dir - let globlinks = vimwiki#base#get_globlinks() + " convert to a List let lst = split(globlinks, '\n') + " Apply fnameescape() to each item call map(lst, 'fnameescape(v:val)') + " Convert back to newline-separated list let globlinks = join(lst, "\n") + " return all escaped links as a single newline-separated string return globlinks endfunction " }}} @@ -1815,13 +1812,6 @@ endfunction "}}} " Command completion functions {{{ -" vimwiki#base#complete_links -function! vimwiki#base#complete_links(ArgLead, CmdLine, CursorPos) abort " {{{ - " We can safely ignore args if we use -custom=complete option, Vim engine - " will do the job of filtering. - return vimwiki#base#get_globlinks() -endfunction " }}} - " vimwiki#base#complete_links_escaped function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort " {{{ " We can safely ignore args if we use -custom=complete option, Vim engine