2020-08-09 22:13:53 +02:00
|
|
|
" TODO treat if local (see $HOME in all tests)
|
|
|
|
" TODO mutualise call CopyResources()
|
|
|
|
" TODO mutualise (to prettify output) mode(1) to check if in -Es or not
|
|
|
|
" TODO test tabnext in at least one travis job (without -Es)
|
|
|
|
" TODO (idea) fasten travis difefrent job with the same vimwiki git (-8s)
|
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
" Declare tipical Vim preambule
|
2020-07-30 05:29:03 +02:00
|
|
|
" vint: -ProhibitSetNoCompatible
|
|
|
|
set nocompatible
|
|
|
|
filetype plugin indent on
|
|
|
|
syntax enable
|
|
|
|
|
2020-08-09 22:13:53 +02:00
|
|
|
" Usefull var: for one day, making tests on local
|
|
|
|
let $TPLUGIN = '/testplugin'
|
|
|
|
let $THOME = $HOME
|
2019-07-14 15:32:38 +02:00
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
" Set chrooted virtual runtime path
|
2020-07-30 05:29:03 +02:00
|
|
|
let rtp=$ROOT.'/rtp.vim'
|
|
|
|
exe 'source '.rtp
|
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
|
|
|
|
" Load Vader
|
2020-07-30 05:29:03 +02:00
|
|
|
let vader=$ROOT.'/vader'
|
|
|
|
exe 'set runtimepath+='.vader
|
|
|
|
|
|
|
|
|
|
|
|
" Wikis configuration
|
|
|
|
" Declare default syntax
|
|
|
|
let vimwiki_default = {}
|
|
|
|
let vimwiki_default.path = $HOME . '/testwiki'
|
|
|
|
let vimwiki_default.path_html = $HOME . '/html/default'
|
|
|
|
let vimwiki_default.syntax = 'default'
|
|
|
|
let vimwiki_default.ext = '.wiki'
|
|
|
|
let vimwiki_default.name = 'DefaultSyntax'
|
|
|
|
let vimwiki_default.base_url = 'https://example.com/'
|
2020-08-02 04:28:32 +02:00
|
|
|
|
2020-07-30 05:29:03 +02:00
|
|
|
" Declare markdown syntax - https://github.github.com/gfm/
|
|
|
|
let vimwiki_markdown = {}
|
|
|
|
let vimwiki_markdown.path = $HOME . '/testmarkdown'
|
|
|
|
let vimwiki_markdown.path_html = $HOME . '/html/markdown'
|
|
|
|
let vimwiki_markdown.syntax = 'markdown'
|
|
|
|
let vimwiki_markdown.ext = '.md'
|
|
|
|
let vimwiki_markdown.name = 'MarkdownSyntax'
|
2020-08-02 04:28:32 +02:00
|
|
|
|
2020-07-30 05:29:03 +02:00
|
|
|
" Declare mediawiki syntax - https://www.mediawiki.org/wiki/Help:Formatting
|
|
|
|
let vimwiki_mediawiki = {}
|
|
|
|
let vimwiki_mediawiki.path = $HOME . '/testmediawiki'
|
|
|
|
let vimwiki_mediawiki.path_html = $HOME . '/html/mediawiki'
|
|
|
|
let vimwiki_mediawiki.syntax = 'media'
|
|
|
|
let vimwiki_mediawiki.ext = '.mw'
|
|
|
|
let vimwiki_mediawiki.name = 'MediaWikiSyntax'
|
2020-08-02 04:28:32 +02:00
|
|
|
|
2020-07-30 05:29:03 +02:00
|
|
|
" Register the 3 wikis
|
|
|
|
let g:vimwiki_list = [vimwiki_default, vimwiki_markdown, vimwiki_mediawiki]
|
2020-08-09 22:13:53 +02:00
|
|
|
let g:vimwiki_list_vimrc = [vimwiki_default, vimwiki_markdown, vimwiki_mediawiki]
|
2020-07-30 05:29:03 +02:00
|
|
|
|
2019-07-15 05:50:49 +02:00
|
|
|
|
2020-07-26 05:26:31 +02:00
|
|
|
" Set basic settings
|
2020-08-09 22:13:53 +02:00
|
|
|
" Avoid more prompt
|
|
|
|
set nomore
|
2020-07-30 05:29:03 +02:00
|
|
|
set backspace=indent,eol,start
|
|
|
|
set wildmode=longest:full,full
|
|
|
|
set wildmenu
|
|
|
|
set wildignorecase
|
|
|
|
set splitbelow
|
|
|
|
set splitright
|
|
|
|
set timeoutlen=600
|
|
|
|
set ignorecase
|
|
|
|
set smartcase
|
|
|
|
set hidden
|
|
|
|
set laststatus=2
|
|
|
|
set hlsearch
|
|
|
|
|
|
|
|
|
|
|
|
" Map
|
|
|
|
" Map ctrl-p/n for history completion instead of up/down arrows
|
|
|
|
cnoremap <C-p> <Up>
|
|
|
|
cnoremap <C-n> <Down>
|
2020-08-02 04:28:32 +02:00
|
|
|
|
2020-07-30 05:29:03 +02:00
|
|
|
" Map jj to go back to command mode
|
|
|
|
inoremap jj <esc>
|
2020-08-02 04:28:32 +02:00
|
|
|
|
2020-07-30 05:29:03 +02:00
|
|
|
" Use <C-L> to clear the highlighting of :set hlsearch and also preserve the
|
|
|
|
" default behavior of redrawing the screen
|
|
|
|
if maparg('<C-L>', 'n') ==# ''
|
|
|
|
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
|
|
|
|
endif
|
|
|
|
|
|
|
|
" 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'
|
|
|
|
elseif a:vw_syn ==# 'media'
|
|
|
|
let ext = 'mw'
|
|
|
|
else
|
|
|
|
Log 'ERROR: Invalid syntax "' . a:vw_syn . '" in SetSyntax()'
|
|
|
|
Log 'NOTE: function only accepts "media" for setting mediawiki syntax'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let path = expand('%:p:h')
|
|
|
|
let new_temp_wiki_settings = {'path': path,
|
|
|
|
\ 'ext': ext,
|
|
|
|
\ 'syntax': a:vw_syn,
|
|
|
|
\ }
|
|
|
|
|
|
|
|
" 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
|
|
|
|
call vimwiki#vars#add_temporary_wiki(new_temp_wiki_settings)
|
|
|
|
call vimwiki#vars#set_bufferlocal('wiki_nr', 3)
|
|
|
|
|
|
|
|
" 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
|
|
|
|
|
2020-08-09 22:13:53 +02:00
|
|
|
" UNlet what can be
|
|
|
|
for i in ['g:vimwiki_commentstring',
|
|
|
|
\ 'b:did_ftplugin',
|
|
|
|
\ 'g:loaded_vimwiki',
|
|
|
|
\ 'g:vimwiki_global_vars',
|
|
|
|
\ 'g:vimwiki_wikilocal_vars',
|
|
|
|
\ 'g:vimwiki_syntax_variables',
|
|
|
|
\ ]
|
|
|
|
if exists(i)
|
|
|
|
exe 'unlet ' . i
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" Reset list
|
|
|
|
let g:vimwiki_list = g:vimwiki_list_vimrc
|
|
|
|
|
|
|
|
" Source plugin: Go
|
|
|
|
runtime! plugin/vimwiki.vim
|
2020-07-30 05:29:03 +02:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ReloadVars()
|
|
|
|
" vars#init will not reload syntax varaible if not set
|
|
|
|
unlet g:vimwiki_syntax_variables
|
|
|
|
call vimwiki#vars#init()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" 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()
|
|
|
|
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
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Write current file: helper to hide `set bt=`
|
|
|
|
function! WriteMe()
|
|
|
|
set buftype=
|
|
|
|
write %
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Delete a file <- path <string>
|
|
|
|
function! DeleteFile(path)
|
|
|
|
let path = expand(a:path)
|
|
|
|
" Delete file
|
|
|
|
try
|
|
|
|
call delete(path)
|
|
|
|
catch | endtry
|
|
|
|
" Delete Buffer
|
|
|
|
try
|
2020-08-09 22:13:53 +02:00
|
|
|
execute 'bwipeout! ' . path
|
2020-07-30 05:29:03 +02:00
|
|
|
catch | endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Print a command output to the buffer
|
|
|
|
function! PrintCommand(cmd)
|
|
|
|
redir => message
|
|
|
|
silent execute a:cmd
|
|
|
|
redir END
|
|
|
|
if empty(message)
|
|
|
|
Log 'no output'
|
|
|
|
else
|
|
|
|
silent put=message
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" 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
|
|
|
|
|
|
|
|
" Convert current buffer: wiki -> html
|
|
|
|
" No side effect (if no bug)
|
|
|
|
function! ConvertWiki2Html()
|
|
|
|
" Save fbuffer number (to come back)
|
|
|
|
let g:buf_vader = bufnr('%')
|
|
|
|
|
|
|
|
" Cut wiki content
|
|
|
|
let wiki_content = getline(1, '$')
|
|
|
|
1,$delete
|
|
|
|
|
|
|
|
" Paste to a named file
|
2020-08-02 04:28:32 +02:00
|
|
|
" Edit a new file in wiki_root
|
2020-07-30 05:29:03 +02:00
|
|
|
edit $HOME/testwiki/test_Convert2Html.wiki
|
|
|
|
" Ensure it is void
|
|
|
|
1,$delete
|
|
|
|
" Write wiki content
|
|
|
|
call setline(1, wiki_content)
|
|
|
|
" Dump buffer to disk
|
|
|
|
call WriteMe()
|
|
|
|
|
|
|
|
" Convert
|
|
|
|
"""""""""
|
|
|
|
Vimwiki2HTML
|
|
|
|
|
|
|
|
" Cut output
|
|
|
|
edit $HOME/html/default/test_Convert2Html.html
|
|
|
|
let html_content = getline(1, '$')
|
|
|
|
1,$delete
|
|
|
|
|
|
|
|
" Paste output in [Vader] buffer
|
|
|
|
execute 'buffer ' . g:buf_vader
|
|
|
|
call setline(1, html_content)
|
|
|
|
|
|
|
|
" Delete files
|
|
|
|
call DeleteFile('$HOME/html/default/test_Convert2Html.html')
|
|
|
|
call DeleteFile('$HOME/testwiki/test_Convert2Html.wiki')
|
|
|
|
endfunction
|
|
|
|
|
2020-08-02 04:28:32 +02:00
|
|
|
|
|
|
|
" Get normalized syntax group: usefull for boldItalic Vs italicBold
|
|
|
|
" -- Here, Vader's SyntaxAt is not enough
|
|
|
|
" From: https://stackoverflow.com/questions/9464844
|
|
|
|
function! GetSyntaxGroup(line, col)
|
|
|
|
let l:s = synID(a:line, a:col, 1)
|
|
|
|
return synIDattr(synIDtrans(l:s), 'name')
|
|
|
|
endfun
|
|
|
|
|
2020-07-30 05:29:03 +02:00
|
|
|
" vim: ft=vim:sw=2
|