vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 990b25ce37bbeb8a8c8f9208c0f8f455202041db
parent 1ea97303fd9c09d4bd005d1c1dadfb2badebc60a
Author: mtourneb <martin.tourneboeuf@alma.cl>
Date:   Sat,  5 Sep 2020 16:12:46 -0400

Fix: Folding by 'syntax' does nothing with Markdown syntax (Issue #1009)

Diffstat:
Mautoload/vimwiki/vars.vim | 47++++++++++++++++++++++++-----------------------
Mdoc/vimwiki.txt | 4+++-
Msyntax/vimwiki.vim | 23++++++++++++-----------
Msyntax/vimwiki_markdown_custom.vim | 10----------
Atest/fold.vader | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/list_return.vader | 7+++++++
Mtest/syntax.vader | 7+++++--
Mtest/vimrc | 19++++++++++++++++++-
8 files changed, 128 insertions(+), 48 deletions(-)

diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim @@ -579,38 +579,35 @@ function! s:populate_wikilocal_options() abort let temp_dic.is_temporary_wiki = 1 call add(g:vimwiki_wikilocal_vars, temp_dic) - " Check some values individually - """""""""""""""""""""""""""""""" + " Normalize and leave + call s:normalize_wikilocal_settings() +endfunction - " Set up variables for the lists, depending on config and syntax - for wiki in g:vimwiki_wikilocal_vars + +" Normalize local settings +function! s:normalize_wikilocal_settings() abort + for wiki_settings in g:vimwiki_wikilocal_vars + " Check some values individually + """""""""""""""""""""""""""""""" " Treat lists " TODO remove me: I am syntaxlocal - if !has_key(wiki, 'bullet_types') || len(wiki.bullet_types) == 0 - let wiki.bullet_types = vimwiki#vars#get_syntaxlocal('bullet_types', wiki.syntax) + if !has_key(wiki_settings, 'bullet_types') || len(wiki_settings.bullet_types) == 0 + let wiki_settings.bullet_types = vimwiki#vars#get_syntaxlocal('bullet_types', wiki_settings.syntax) endif - call s:populate_list_vars(wiki) + call s:populate_list_vars(wiki_settings) " Check nested syntax - for keyword in keys(wiki.nested_syntaxes) - if type(keyword) != type('') || empty(keyword) || type(wiki.nested_syntaxes[keyword]) != type('') || - \ empty(wiki.nested_syntaxes[keyword]) + for keyword in keys(wiki_settings.nested_syntaxes) + if type(keyword) != type('') || empty(keyword) || type(wiki_settings.nested_syntaxes[keyword]) != type('') || + \ empty(wiki_settings.nested_syntaxes[keyword]) call vimwiki#u#error(printf('The provided value ''%s'' of the option ''g:vimwiki_%s'' is' - \ . ' invalid. See '':h g:vimwiki_%s''.', string(wiki.nested_syntaxes), 'nested_syntaxes', 'nested_syntaxes')) + \ . ' invalid. See '':h g:vimwiki_%s''.', string(wiki_settings.nested_syntaxes), 'nested_syntaxes', 'nested_syntaxes')) break endif endfor - endfor - - " Normalize and leave - call s:normalize_wikilocal_settings() -endfunction - - -" Normalize local settings -function! s:normalize_wikilocal_settings() abort - for wiki_settings in g:vimwiki_wikilocal_vars + " Nomarlize + """""""""""""""""""""""""""""""" let wiki_settings['path'] = s:normalize_path(wiki_settings['path']) let path_html = wiki_settings['path_html'] @@ -910,7 +907,7 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort \ .header_symbol.'\{'.i.'}\s*$' let syntax_dic['rxH'.i.'_End'] = \ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']' - \ .header_symbol.'\{1,'.i.'}\s*$' + \ .header_symbol.'\{1,'.i.'}\s*$\|\%$' endfor let syntax_dic.rxHeader = \ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze\1\s*$' @@ -927,7 +924,7 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort let syntax_dic['rxH'.i.'_Start'] = \ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$' let syntax_dic['rxH'.i.'_End'] = - \ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$' + \ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$\|\%$' endfor " Define header regex " -- ATX heading := preceed by #* @@ -1036,8 +1033,10 @@ endfunction " Populate list variable " or how to search and treat list (ex: *,-, 1.) +" TODO this should be syntax_local function! s:populate_list_vars(wiki) abort let syntax = a:wiki.syntax + let syntax_dic = g:vimwiki_syntaxlocal_vars[syntax] let a:wiki.rx_bullet_char = '['.escape(join(a:wiki.bullet_types, ''), ']^-\').']' let a:wiki.rx_bullet_chars = a:wiki.rx_bullet_char.'\+' @@ -1641,6 +1640,8 @@ function! vimwiki#vars#add_temporary_wiki(settings) abort let new_temp_wiki_settings = copy(g:vimwiki_wikilocal_vars[-1]) for [key, value] in items(a:settings) let new_temp_wiki_settings[key] = value + " Remove users_value to prevent type mismatch (E706) errors in vim <7.4.1546 (Issue #681) + unlet value endfor call insert(g:vimwiki_wikilocal_vars, new_temp_wiki_settings, -1) call s:normalize_wikilocal_settings() diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -3024,7 +3024,6 @@ Limitations: - Opening very large files may be slow when folding is enabled. - 'list' folding is particularly slow with larger files. - 'list' is intended to work with lists nicely indented with 'shiftwidth'. - - 'syntax' is only available for the default syntax so far. The options above can be suffixed with ':quick' (e.g.: 'expr:quick') in order to use some workarounds to make folds work faster. @@ -3840,6 +3839,9 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from https://github.com/vimwiki-backup/vimwiki/issues. New:~ + * Issue #1009: |foldmethod| syntax works for markdown (|g:vimwiki_folding|) + Also the VimwikiHeader1Folding (1..60 regions support end-of-file `/\%$` + as end maker * Issue #990: Feature request: highlight multiline selection Add :VimwikiColorize with only support to clorize the current line * PR #919: Fix duplicate helptag diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim @@ -149,19 +149,22 @@ let s:target = vimwiki#base#apply_template( call s:add_target_syntax_ON(s:target, 'VimwikiLink') - " Header Level: 1..6 for s:i in range(1,6) + " WebLink are for markdown but putting them here avoidcode duplication + " -- and syntax folding Issue #1009 execute 'syntax match VimwikiHeader'.s:i - \ . ' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i, s:current_syntax). - \ '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'. - \ 'VimwikiLink,@Spell' - execute 'syntax region VimwikiH'.s:i.'Folding start=/'. - \ vimwiki#vars#get_syntaxlocal('rxH'.s:i.'_Start', s:current_syntax).'/ end=/'. - \ vimwiki#vars#get_syntaxlocal('rxH'.s:i.'_End', s:current_syntax). - \ '/me=s-1 transparent fold' + \ . ' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i, s:current_syntax) + \ . '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,' + \ . 'VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,VimwikiList,VimwikiListTodo,@Spell' + execute 'syntax region VimwikiH'.s:i.'Folding start=/' + \ . vimwiki#vars#get_syntaxlocal('rxH'.s:i.'_Start', s:current_syntax).'/ end=/' + \ . vimwiki#vars#get_syntaxlocal('rxH'.s:i.'_End', s:current_syntax) + \ . '/me=s-1' + \ . ' transparent fold' endfor + " SetExt Header: " TODO mutualise SetExt Regexp let setex_header1_re = '^\s\{0,3}[^>].*\n\s\{0,3}==\+$' @@ -209,11 +212,9 @@ execute 'syn match VimwikiHeaderChar contained /\%(^\s*'. \ vimwiki#vars#get_syntaxlocal('header_symbol').'\+\)\|\%('.vimwiki#vars#get_syntaxlocal('header_symbol'). \ '\+\s*$\)/' - execute 'syntax match VimwikiTodo /'. vimwiki#vars#get_global('rxTodo') .'/' - " Table: syntax match VimwikiTableRow /^\s*|.\+|\s*$/ \ transparent contains=VimwikiCellSeparator, @@ -234,7 +235,6 @@ syntax match VimwikiTableRow /^\s*|.\+|\s*$/ syntax match VimwikiCellSeparator /\%(|\)\|\%(-\@<=+\-\@=\)\|\%([|+]\@<=-\+\)/ contained - " List: execute 'syntax match VimwikiList /'.vimwiki#vars#get_wikilocal('rxListItemWithoutCB').'/' execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListDefine').'/' @@ -345,6 +345,7 @@ if exists('+conceallevel') && tf.conceal != 0 endif execute tag_cmd + " Header Groups: highlighting if vimwiki#vars#get_global('hl_headers') == 0 " Strangely in default colorscheme Title group is not set to bold for cterm... diff --git a/syntax/vimwiki_markdown_custom.vim b/syntax/vimwiki_markdown_custom.vim @@ -123,16 +123,6 @@ let s:target = vimwiki#base#apply_template( call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1') - -" Header levels, 1-6 -for s:i in range(1,6) - execute 'syntax match VimwikiHeader'.s:i.' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i). - \ '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'. - \ 'VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell' -endfor - - - " concealed chars if exists('+conceallevel') syntax conceal on diff --git a/test/fold.vader b/test/fold.vader @@ -0,0 +1,59 @@ +# Fold + +Execute (Save state): + Log 'Previous foldmethod: ' . &foldmethod + let save_foldmethod = &foldmethod + +Given vimwiki (Markdown Headers): + Some stuff 1 + # Header level 1 2 + ## Header level 2 3 + Content 4 + ### Header level 3 5 + # Header level 1 6 + Content 7 + ## Just to end 8: Vader cannot match end-of-file + +Execute (Markdown and Fold Syntax): + call SetSyntax('markdown') + set foldmethod=syntax + +Execute (Assert Markdown: Fold Syntax): + Log 'Supposing it starts at foldlevel 0' + AssertEqual 'line 1:0', 'line 1:' . foldlevel(1) + AssertEqual 'line 2:0', 'line 2:' . foldlevel(2) + AssertEqual 'line 3:1', 'line 3:' . foldlevel(3) + AssertEqual 'line 4:2', 'line 4:' . foldlevel(4) + AssertEqual 'line 5:2', 'line 5:' . foldlevel(5) + AssertEqual 'line 6:0', 'line 6:' . foldlevel(6) + AssertEqual 'line 7:0', 'line 7:' . foldlevel(7) + + +Given vimwiki (Wiki Headers): + Some stuff 1 + = Header level 1 2 = + == Header level 2 3 == + Content 4 + === Header level 3 5 === + = Header level 1 6 = + Content 7 + == Just to end 8 == + +Execute (Markdown and Fold Syntax): + call SetSyntax('default') + set foldmethod=syntax + +Execute (Assert Markdown: Fold Syntax): + Log 'Supposing it starts at foldlevel 0' + AssertEqual 'line 1:0', 'line 1:' . foldlevel(1) + AssertEqual 'line 2:0', 'line 2:' . foldlevel(2) + AssertEqual 'line 3:1', 'line 3:' . foldlevel(3) + AssertEqual 'line 4:2', 'line 4:' . foldlevel(4) + AssertEqual 'line 5:2', 'line 5:' . foldlevel(5) + AssertEqual 'line 6:0', 'line 6:' . foldlevel(6) + AssertEqual 'line 7:0', 'line 7:' . foldlevel(7) + +Execute (Restore state): + let &foldmethod = save_foldmethod + Log 'Next foldmethod: ' . &foldmethod + diff --git a/test/list_return.vader b/test/list_return.vader @@ -2,8 +2,15 @@ # # Note: some trailing spaces are necessary at the end of list items like `1.` # better read this file with `set list` +# +# Warning: Foldmethod dependant (and foldlevel ...) +Execute (Save State): + let msg = 'Error: foldmethod must be manual for theses tests to work,' + let msg .= ' it is the default, so please restore it in the test that changed it' + AssertEqual &foldmethod, 'manual', msg + Given vimwiki (List Blockquote (Issue #55) {{{2): 1. Outer Item 1 1. Inner Item 1 diff --git a/test/syntax.vader b/test/syntax.vader @@ -467,7 +467,7 @@ Given vimwiki (Wiki Headers): Execute (Set syntax default): call SetSyntax('default') -Execute (Assert Syntax Header): +Execute (Assert Wiki Syntax Header): AssertEqual 'VimwikiHeader1', SyntaxAt(1, 10) AssertEqual 'VimwikiHeader2', SyntaxAt(2, 10) AssertEqual 'VimwikiHeader3', SyntaxAt(3, 10) @@ -486,7 +486,10 @@ Given vimwiki (Markdown Headers): Execute (Set syntax markdown): call SetSyntax('markdown') -Execute (Assert Syntax Header): +Execute (Assert Markdown Syntax Header): + Log "Syntax of first heading: " . string(GetSyntaxStack()) + Log "Regex of rxListWithoutCb: " . vimwiki#vars#get_wikilocal('rxListItemWithoutCB') + Log "Bullet types: " . string(vimwiki#vars#get_wikilocal('bullet_types')) AssertEqual 'VimwikiHeader1' , SyntaxAt(1, 10) AssertEqual 'VimwikiHeader2' , SyntaxAt(2, 10) AssertEqual 'VimwikiHeader3' , SyntaxAt(3, 10) diff --git a/test/vimrc b/test/vimrc @@ -89,21 +89,30 @@ " Define functions " Change the syntax using a temporary wiki function! SetSyntax(vw_syn) + " Change extension and wiki_nr + let index=0 if a:vw_syn ==# 'default' let ext = 'wiki' + let index=0 elseif a:vw_syn ==# 'markdown' let ext = 'md' + let index=1 elseif a:vw_syn ==# 'media' let ext = 'mw' + let index=2 else Log 'ERROR: Invalid syntax "' . a:vw_syn . '" in SetSyntax()' Log 'NOTE: function only accepts "media" for setting mediawiki syntax' return endif + + " Change temporary wiki let path = expand('%:p:h') - let new_temp_wiki_settings = {'path': path, + let new_temp_wiki_settings = { + \ 'path': path, \ 'ext': ext, \ 'syntax': a:vw_syn, + \ 'bullet_types': g:vimwiki_wikilocal_vars[index]['bullet_types'], \ } " Remove any temporary wikis each time this function is called. @@ -306,6 +315,14 @@ return synIDattr(synIDtrans(l:s), 'name') endfun + " Debug helper + function! GetSyntaxStack() + if !exists('*synstack') + return + endif + return map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') + endfunc + " Run Assert only if vim version higth enough function! AssertIfVersion(version, one, two) if v:version < a:version | return | endif