Fix test failures.
Change document of Pythonic folding.
let g:vim_markdown_folding_style_pythonic = 1
- Level 1 heading which is served as a document title is not folded.
- `g:vim_markdown_folding_level` setting is not active with this fold style.
+ `g:vim_markdown_folding_level` setting (default 1) is set to `foldlevel`.
+ Thus level 1 heading which is served as a document title is expanded by default.
- `g:vim_markdown_override_foldtext`
-" vim: ts=4:
+" vim: ts=4 sw=4:
" folding for Markdown headers, both styles (atx- and setex-)
" http://daringfireball.net/projects/markdown/syntax#header
"
let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1
return line . ' ' . repeat("-", fillcharcount) . ' ' . foldedlinecount
endfunction
-else " vim_markdown_folding_style_pythonic == 1
+else " vim_markdown_folding_style_pythonic == 0
function! Foldexpr_markdown(lnum)
if (a:lnum == 1)
let l0 = ''
let s:vim_markdown_folding_level = get(g:, "vim_markdown_folding_level", 1)
function! s:MarkdownSetupFolding()
- if !get(g:, "vim_markdown_folding_disabled", 0)
- setlocal foldexpr=Foldexpr_markdown(v:lnum)
- setlocal foldmethod=expr
- if get(g:, "vim_markdown_folding_style_pythonic", 0) && get(g:, "vim_markdown_override_foldtext", 1)
- setlocal foldtext=Foldtext_markdown()
- endif
- endif
+ if !get(g:, "vim_markdown_folding_disabled", 0)
+ if get(g:, "vim_markdown_folding_style_pythonic", 0)
+ if get(g:, "vim_markdown_override_foldtext", 1)
+ setlocal foldtext=Foldtext_markdown()
+ endif
+ endif
+ setlocal foldexpr=Foldexpr_markdown(v:lnum)
+ setlocal foldmethod=expr
+ endif
+endfunction
+
+function! s:MarkdownSetupFoldLevel()
+ if get(g:, "vim_markdown_folding_style_pythonic", 0)
+ " set default foldlevel
+ execute "setlocal foldlevel=".s:vim_markdown_folding_level
+ endif
endfunction
+
+call s:MarkdownSetupFoldLevel()
call s:MarkdownSetupFolding()
+
augroup Mkd
" These autocmds need to be kept in sync with the autocmds calling
" s:MarkdownRefreshSyntax in ftplugin/markdown.vim.
foobar
Execute (fold level # in code block):
- AssertEqual foldlevel(1), 0, '# Title'
- AssertEqual foldlevel(3), 1, '## Chapter 1'
- AssertEqual foldlevel(7), 1, '# This is just a comment'
- AssertEqual foldlevel(8), 1, '```'
- AssertEqual foldlevel(10), 1, '## Chapter 2'
- AssertEqual foldlevel(12), 1, 'foobar'
+ AssertEqual foldlevel(1), 1, '# Title'
+ AssertEqual foldlevel(3), 2, '## Chapter 1'
+ AssertEqual foldlevel(7), 2, '# This is just a comment'
+ AssertEqual foldlevel(8), 2, '```'
+ AssertEqual foldlevel(10), 2, '## Chapter 2'
+ AssertEqual foldlevel(12), 2, 'foobar'
Execute (fold text of chapters):
let b:width = winwidth(0)
let b:hyphen = repeat('-', b:width - 18 > 2 ? b:width - 18 : b:width - 9 > 0 ? 3 : 2)
- AssertEqual foldtextresult(3), strpart('## Chapter 1', 0, b:width - 9) . ' ' . b:hyphen . ' 6'
AssertEqual foldtextresult(10), strpart('## Chapter 2', 0, b:width - 9) . ' ' . b:hyphen . ' 2'
Given markdown;
Execute (fold any preamble):
AssertEqual foldlevel(1), 1, 'Headline'
AssertEqual foldlevel(3), 1, 'foobar'
- AssertEqual foldlevel(5), 0, '# Title'
+ AssertEqual foldlevel(5), 1, '# Title'
Given markdown;
---