2019-07-15 05:50:22 +02:00
|
|
|
Before (Define functions):
|
|
|
|
" change the syntax using a temporary wiki
|
|
|
|
function! SetSyntax(vw_syn)
|
|
|
|
if a:vw_syn ==# 'default'
|
|
|
|
let ext = 'wiki'
|
|
|
|
elseif a:vw_syn ==# 'markdown'
|
|
|
|
let ext = 'md'
|
2019-07-17 15:13:36 +02:00
|
|
|
elseif a:vw_syn ==# 'media'
|
2019-07-15 05:50:22 +02:00
|
|
|
let ext = 'mw'
|
|
|
|
else
|
2019-07-17 15:13:36 +02:00
|
|
|
Log 'ERROR: Invalid syntax "' . a:vw_syn . '" in SetSyntax()'
|
|
|
|
Log 'NOTE: function only accepts "media" for setting mediawiki syntax'
|
2019-07-15 05:50:22 +02:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
let path = expand('%:p:h')
|
|
|
|
let new_temp_wiki_settings = {'path': path,
|
|
|
|
\ 'ext': ext,
|
|
|
|
\ 'syntax': a:vw_syn,
|
|
|
|
\ }
|
2019-08-22 13:48:20 +02:00
|
|
|
|
|
|
|
" Remove any temporary wikis each time this function is called.
|
|
|
|
" This is necessary to ensure syntax is properly set when running multiple tests
|
|
|
|
" NOTE: this assumes there are 3 defined wikis in the vimrc. The last wiki
|
|
|
|
" contains default settings for temporary wikis (so there are always
|
|
|
|
" num wikis in vimrc + 1)
|
|
|
|
let num_wikis = len(g:vimwiki_wikilocal_vars)
|
|
|
|
while num_wikis > 4
|
|
|
|
call remove(g:vimwiki_wikilocal_vars, num_wikis - 1)
|
|
|
|
let num_wikis = num_wikis - 1
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
" add the new wiki
|
2019-07-15 05:50:22 +02:00
|
|
|
call vimwiki#vars#add_temporary_wiki(new_temp_wiki_settings)
|
2019-08-22 13:48:20 +02:00
|
|
|
call vimwiki#vars#set_bufferlocal('wiki_nr', 3)
|
2019-07-17 15:13:36 +02:00
|
|
|
|
|
|
|
" verify syntax was set correctly
|
|
|
|
Assert vimwiki#vars#get_wikilocal('syntax') ==# a:vw_syn, 'ERROR: Vimwiki syntax not set correctly.'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" reload plugin to change settings
|
|
|
|
function! ReloadVimwiki()
|
|
|
|
" clear mappings so plugin can be reloaded
|
|
|
|
" this is needed if running manually multiple times
|
|
|
|
nmapclear
|
2019-08-22 13:48:20 +02:00
|
|
|
|
2019-07-17 15:13:36 +02:00
|
|
|
unlet g:loaded_vimwiki
|
|
|
|
source plugin/vimwiki.vim
|
2019-07-15 05:50:22 +02:00
|
|
|
endfunction
|
2019-12-15 05:37:28 +01:00
|
|
|
|
|
|
|
" Copy wiki test resources so that vimtest user can write them
|
|
|
|
function! CopyResources()
|
|
|
|
call system('cp -r /testplugin/test/resources/* $HOME/')
|
|
|
|
" Make diary directory
|
|
|
|
call system('mkdir $HOME/testwiki/diary')
|
|
|
|
call system('mkdir $HOME/testmarkdown/diary')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Delete Hidden buffer, usefull to clean
|
|
|
|
" Stole from: https://stackoverflow.com/a/8459043/2544873
|
|
|
|
function! DeleteHiddenBuffers()
|
2020-01-05 05:21:52 +01:00
|
|
|
let tpbl=[]
|
|
|
|
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
|
|
|
|
for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
|
|
|
|
if bufname(buf) =~ 'Vader'
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
silent execute 'bwipeout!' buf
|
|
|
|
endfor
|
2019-12-15 05:37:28 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Write current file: helper to hide `set bt=`
|
|
|
|
function! WriteMe()
|
2019-12-21 17:10:39 +01:00
|
|
|
set buftype=
|
2019-12-15 05:37:28 +01:00
|
|
|
write %
|
|
|
|
endfunction
|
|
|
|
|
2020-06-16 19:46:25 +02:00
|
|
|
" Print a command output to the buffer
|
2019-12-21 17:10:39 +01:00
|
|
|
function! PrintCommand(cmd)
|
|
|
|
redir => message
|
|
|
|
silent execute a:cmd
|
|
|
|
redir END
|
|
|
|
if empty(message)
|
|
|
|
Log 'no output'
|
|
|
|
else
|
|
|
|
silent put=message
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2020-06-16 19:46:25 +02:00
|
|
|
" Destroy a variable is exists (unlet)
|
|
|
|
function! DestroyVar(var)
|
|
|
|
if ! exists(a:var) | return | endif
|
|
|
|
execute "unlet " . a:var
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Assert current tab is desired tab
|
|
|
|
function! AssertTab(nr)
|
|
|
|
" Vader is creating 2 tabs
|
|
|
|
AssertEqual a:nr + 2, tabpagenr()
|
|
|
|
endfunction
|
|
|
|
|
2019-12-15 05:37:28 +01:00
|
|
|
# vim: ft=vim
|