Refactor: Test & Doc: Remove test/vader_include and move DesignNotes to doc
- vader_include is declareing functions -> faster to load (parse) once in vimrc - DesignNotes is doc so goes to doc
This commit is contained in:
parent
96232c0340
commit
2332dc1514
@ -253,7 +253,7 @@ VimWiki has a lot of users but only very few recurring developers or people
|
||||
helping the community. Your help is therefore appreciated. Everyone can help!
|
||||
See [#625](https://github.com/vimwiki/vimwiki/issues/625) for information on how you can help.
|
||||
|
||||
Also, take a look at [CONTRIBUTING.md](https://github.com/vimwiki/vimwiki/blob/master/CONTRIBUTING.md).
|
||||
Also, take a look at [CONTRIBUTING.md](https://github.com/vimwiki/vimwiki/blob/master/CONTRIBUTING.md) and [DesignNotes.md](doc/DesignNotes.md)
|
||||
|
||||
----
|
||||
|
||||
|
@ -1,4 +1,8 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Automatic link generation
|
||||
# Related to:
|
||||
# - wiki file discovery
|
||||
# - buffer list insertion (see: vimwiki#base#update_listing_in_buffer)
|
||||
|
||||
|
||||
Execute (Copy Wiki's Resources):
|
||||
Log "Start: Copy Resources"
|
||||
@ -196,7 +200,4 @@ Execute (Clean):
|
||||
Log "End: Reset shiftwidth to the default: 8"
|
||||
set sw&
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
||||
# vim: sw=2:foldmethod=marker:foldlevel=30:foldignore=:
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Tag generation
|
||||
|
||||
Execute (Copy Wiki's Resources):
|
||||
Log "Start: Copy Resources"
|
||||
@ -93,4 +93,4 @@ Execute (Clean Test-Tag and .vimwiki_tags):
|
||||
call system("rm $HOME/testmarkdown/Test-Tag.md")
|
||||
call DeleteHiddenBuffers()
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: sw=2:foldlevel=30:foldmethod=indent:
|
||||
|
@ -1,9 +1,9 @@
|
||||
# VimwikiGoto
|
||||
#
|
||||
# Note: I dont know why <Tab> is inserting a Tab.
|
||||
# Well better than to insert a Chair, but it should trigger completion
|
||||
# So I used C-L
|
||||
|
||||
Include: vader_includes/vader_setup.vader
|
||||
|
||||
|
||||
Execute (Copy Wiki's Resources):
|
||||
Log "Start: Copy Resources"
|
||||
@ -80,5 +80,4 @@ Execute (Clean):
|
||||
Log "End: Clean"
|
||||
call system("rm $HOME/testmarkdown/dir1")
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: sw=2 foldmethod=indent foldlevel=30 foldignore=
|
||||
|
@ -1,4 +1,5 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# VimwikiRenameFile
|
||||
# Related to link, file navigation
|
||||
|
||||
|
||||
# Create directories I remove at end {{{1
|
||||
@ -257,6 +258,4 @@ Execute (Clean dir1 and dir2):
|
||||
call system('rm -r $HOME/testmarkdown/dir2')
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
||||
# vim: sw=2 foldmethod=marker foldlevel=30 foldignore=#
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# VimwikiTOC
|
||||
|
||||
Execute (Reset TOC header to default):
|
||||
let g:vimwiki_global_vars['toc_header'] = "Contents"
|
||||
@ -169,7 +169,4 @@ Expect (Content prepended):
|
||||
# Header 2
|
||||
### Header 2.1.1
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
||||
" vim: sw=2 foldmethod=indent foldlevel=30 foldignore=
|
||||
" vim: sw=2 foldmethod=indent foldlevel=30 foldignore=#
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Conertion: Wiki -> Html
|
||||
|
||||
Execute (Copy Wiki's Resources):
|
||||
Log "Start: Copy Resources"
|
||||
@ -13,23 +13,7 @@ Given vimwiki (Table no heading {{{1):
|
||||
| val1 | val2 |
|
||||
|
||||
Do (Convert):
|
||||
# Note: gg"bdG = Cut
|
||||
# Note: ggdG"bp = Replace file content by clipboard "b
|
||||
# Fill file with a name
|
||||
:let g:buf_vader = bufnr('%')\<Cr>
|
||||
gg"bdG
|
||||
:edit $HOME/testwiki/test_html_table.wiki\<Cr>
|
||||
ggdG"bp
|
||||
:call WriteMe()\<Cr>
|
||||
# Convert
|
||||
:Vimwiki2HTML\<Cr>
|
||||
# Copy output
|
||||
:edit $HOME/html/default/test_html_table.html\<Cr>
|
||||
gg"bdG
|
||||
# Paste output in [Vader] buffer
|
||||
:execute 'buffer ' . g:buf_vader\<Cr>
|
||||
ggdG"bp
|
||||
|
||||
:call ConvertWiki2Html()\<Cr>
|
||||
# Keep only body
|
||||
ggd/<body>\<Cr>
|
||||
|
||||
@ -87,23 +71,7 @@ Given vimwiki (Table with heading {{{1):
|
||||
| val4 | val5 | var6 |
|
||||
|
||||
Do (Convert):
|
||||
# Note: gg"bdG = Cut
|
||||
# Note: ggdG"bp = Replace file content by clipboard "b
|
||||
# Fill file with a name
|
||||
:let g:buf_vader = bufnr('%')\<Cr>
|
||||
gg"bdG
|
||||
:edit $HOME/testwiki/test_html_table.wiki\<Cr>
|
||||
ggdG"bp
|
||||
:call WriteMe()\<Cr>
|
||||
# Convert
|
||||
:Vimwiki2HTML\<Cr>
|
||||
# Copy output
|
||||
:edit $HOME/html/default/test_html_table.html\<Cr>
|
||||
gg"bdG
|
||||
# Paste output in [Vader] buffer
|
||||
:execute 'buffer ' . g:buf_vader\<Cr>
|
||||
ggdG"bp
|
||||
|
||||
:call ConvertWiki2Html()\<Cr>
|
||||
# Keep only body
|
||||
ggd/<body>\<Cr>
|
||||
|
||||
@ -273,5 +241,4 @@ Expect (Plain Html):
|
||||
Execute (Delete):
|
||||
call DeleteFile('$HOME/testwiki/TestHtml.wiki')
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: sw=2 foldmethod=marker foldlevel=30
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Feature to generate a diray RSS feed (PR #934)
|
||||
|
||||
Execute (Copy Wiki's Resources):
|
||||
Log "Start: Copy Resources"
|
||||
@ -106,5 +106,3 @@ Expect (RSS):
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Blockquotes in html convertion
|
||||
|
||||
Execute (Copy Wiki's Resources):
|
||||
Log "Start: Copy Resources"
|
||||
@ -68,4 +68,4 @@ Expect (Plain Html):
|
||||
|
||||
</body>
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: sw=2:foldlevel=30:foldmethod=indent:
|
||||
|
@ -1,6 +1,3 @@
|
||||
Include: vader_setup
|
||||
|
||||
|
||||
# 0 Configure {{{1
|
||||
##################
|
||||
|
||||
@ -566,5 +563,4 @@ Expect (Like 'aH', but excluding the header itself):
|
||||
# Head2
|
||||
content 2
|
||||
|
||||
Include: vader_teardown
|
||||
# vim: foldmethod=marker foldlevel=30 sw=2
|
||||
|
@ -1,5 +1,3 @@
|
||||
Include: vader_setup
|
||||
|
||||
Execute (Setup search testing wrapper):
|
||||
function! TestSearch(search_command, test_name)
|
||||
" Note: after each search, the location list of the current window (0)
|
||||
@ -62,5 +60,3 @@ Execute (Search failure message):
|
||||
silent VimwikiSearch not_exist
|
||||
redir END
|
||||
Assert match(output, 'VimwikiSearch: No match found.') > -1, "expected custom error"
|
||||
|
||||
Include: vader_teardown
|
||||
|
@ -5,9 +5,6 @@
|
||||
#
|
||||
|
||||
|
||||
Include: vader_includes/vader_setup.vader
|
||||
|
||||
|
||||
################################################################################
|
||||
Execute (Log):
|
||||
Log '#915 Vimwiki Markdown Blockquote Syntax issue'
|
||||
@ -166,6 +163,3 @@ Do (No link: <CR><CR>):
|
||||
:call vimwiki#vars#set_global('markdown_create_link', 0)
|
||||
\<CR>\<CR>
|
||||
:AssertEqual expand('%:t'), 'main.md'\<CR>
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
@ -1,4 +1,9 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Link creation: my favorite (Tinmarino)
|
||||
# You know, when pressing Enter:
|
||||
# in mode normal, visual
|
||||
# in OS windows, linux
|
||||
# Seems easy but tests are reaaly needed here
|
||||
|
||||
|
||||
# Link Normalisation {{{1
|
||||
# And configuration
|
||||
@ -363,5 +368,4 @@ Expect (Mediawiki links):
|
||||
[[file.md]]
|
||||
[[file.mw]]
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: foldmethod=marker foldlevel=30
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Link internal to a file
|
||||
|
||||
Given vimwiki (Internal links + one link to filenew):
|
||||
# Contents
|
||||
@ -220,6 +220,3 @@ Expect (Some chars appended at self link):
|
||||
- [ this_is_18_chars My own file](wiki_test)
|
||||
- [Test1](#Test1)
|
||||
- [Test2](#Test2)
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
@ -4,8 +4,6 @@
|
||||
# better read this file with `set list`
|
||||
|
||||
|
||||
Include: vader_includes/vader_setup.vader
|
||||
|
||||
Given vimwiki (List with hard wraps):
|
||||
- Item 1
|
||||
- Item 2
|
||||
@ -279,4 +277,5 @@ Expect (List per VimwikiReturn 3 5):
|
||||
1.
|
||||
|
||||
---
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
||||
# vim: sw=2:foldlevel=30:foldmethod=indent:
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Task List with commands
|
||||
|
||||
Given vimwiki (simple list):
|
||||
* [X] Done 1
|
||||
@ -194,6 +194,3 @@ Expect (only first is removed):
|
||||
* [X] Done 3
|
||||
* [ ] Todo 2
|
||||
* [X] Done 4
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# List indentation <= shiftwidth
|
||||
|
||||
Execute (Create temp directory):
|
||||
silent execute '!mkdir -p $HOME/list_margin/'
|
||||
@ -105,4 +105,4 @@ Expect (Links with margin == 5):
|
||||
Execute (Return to default location & cleanup):
|
||||
cd /testplugin
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: sw=2:foldlevel=30:foldmethod=indent:
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Todo lists
|
||||
|
||||
Given vimwiki (Todo list):
|
||||
* [ ] Chap1
|
||||
@ -247,6 +247,3 @@ Do (Toogle <C-Space>):
|
||||
Expect (Chap1 Done):
|
||||
1. [X] Chap1
|
||||
2. [ ] Chap2
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Task list update
|
||||
|
||||
Given vimwiki (Sample nested list, vimwiki syntax):
|
||||
* [ ] Top Level
|
||||
@ -188,4 +188,4 @@ Expect (Sub-child toggled, parents updated):
|
||||
|
||||
* [X] Sub-sub-child
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: sw=2:foldlevel=30:foldmethod=indent:
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Syntax and Highlight
|
||||
|
||||
|
||||
# 1 Typeface {{{1
|
||||
@ -314,5 +314,4 @@ Execute (Assert math syntax):
|
||||
let syntax_12 = SyntaxAt(12, 1)
|
||||
Assert syntax_12 == 'texStatement' || syntax_5 == 'texMathSymbol'
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: foldmethod=marker foldlevel=30 sw=2
|
||||
|
@ -1,4 +1,5 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# Table autoformating
|
||||
# Very configurable: read doc/DesignNotes.md
|
||||
|
||||
# Do not alter config {{{1
|
||||
##########################
|
||||
@ -213,5 +214,4 @@ Expect (Left justified and :--- -> ----):
|
||||
| 2017-03-14 | Cake |
|
||||
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
# vim: foldmethod=marker foldlevel=30
|
||||
|
@ -1,4 +1,4 @@
|
||||
Include: vader_includes/vader_setup.vader
|
||||
# See Issue #580
|
||||
|
||||
Execute (Set fold method):
|
||||
let g:vimwiki_folding = 'expr:quick'
|
||||
@ -28,5 +28,3 @@ Execute (Expect < 0.5 second delay: Issue #580):
|
||||
Execute (Reset variables):
|
||||
let g:vimwiki_folding = ''
|
||||
call ReloadVimwiki()
|
||||
|
||||
Include: vader_includes/vader_teardown.vader
|
||||
|
@ -1,119 +0,0 @@
|
||||
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'
|
||||
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
|
||||
|
||||
unlet g:loaded_vimwiki
|
||||
source plugin/vimwiki.vim
|
||||
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
|
||||
|
||||
function! DeleteFile(path)
|
||||
let path = expand(a:path)
|
||||
" Delete file
|
||||
try
|
||||
call delete(path)
|
||||
catch | endtry
|
||||
" Delete Buffer
|
||||
try
|
||||
execute 'bdelete! ' . path
|
||||
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
|
||||
|
||||
# vim: ft=vim:sw=2
|
@ -1,6 +0,0 @@
|
||||
After (Cleanup):
|
||||
delfunction SetSyntax
|
||||
delfunction ReloadVimwiki
|
||||
delfunction DeleteHiddenBuffers
|
||||
delfunction WriteMe
|
||||
delfunction PrintCommand
|
166
test/vimrc
166
test/vimrc
@ -4,14 +4,18 @@ set nocompatible
|
||||
filetype plugin indent on
|
||||
syntax enable
|
||||
|
||||
|
||||
" Set chrooted virtual runtime path
|
||||
let rtp=$ROOT.'/rtp.vim'
|
||||
exe 'source '.rtp
|
||||
|
||||
|
||||
" Load Vader
|
||||
let vader=$ROOT.'/vader'
|
||||
exe 'set runtimepath+='.vader
|
||||
|
||||
|
||||
" Wikis configuration
|
||||
" Declare default syntax
|
||||
let vimwiki_default = {}
|
||||
let vimwiki_default.path = $HOME . '/testwiki'
|
||||
@ -40,6 +44,7 @@ let vimwiki_mediawiki.name = 'MediaWikiSyntax'
|
||||
" Register the 3 wikis
|
||||
let g:vimwiki_list = [vimwiki_default, vimwiki_markdown, vimwiki_mediawiki]
|
||||
|
||||
|
||||
" Set basic settings
|
||||
set backspace=indent,eol,start
|
||||
set wildmode=longest:full,full
|
||||
@ -54,6 +59,8 @@ 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>
|
||||
@ -66,3 +73,162 @@ inoremap jj <esc>
|
||||
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
|
||||
|
||||
unlet g:loaded_vimwiki
|
||||
source plugin/vimwiki.vim
|
||||
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
|
||||
execute 'bdelete! ' . path
|
||||
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
|
||||
" Edit a new file in wiki_root
|
||||
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
|
||||
|
||||
" vim: ft=vim:sw=2
|
||||
|
Loading…
Reference in New Issue
Block a user