From 9f4d1c8db08cca85c46de7f3f0b944ce3cafe35c Mon Sep 17 00:00:00 2001 From: Hiroshi Shirosaki Date: Wed, 5 Jun 2019 14:52:34 +0900 Subject: [PATCH 1/1] Pythonic folding expand level 1 by default Fix test failures. Change document of Pythonic folding. --- README.md | 4 ++-- after/ftplugin/markdown.vim | 30 +++++++++++++++++++++--------- test/python-folding.vader | 15 +++++++-------- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 6695b06..fd3be68 100644 --- a/README.md +++ b/README.md @@ -108,8 +108,8 @@ Try `:help concealcursor` and `:help conceallevel` for details. 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` diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim index 89d1c38..8be6ff9 100644 --- a/after/ftplugin/markdown.vim +++ b/after/ftplugin/markdown.vim @@ -1,4 +1,4 @@ -" vim: ts=4: +" vim: ts=4 sw=4: " folding for Markdown headers, both styles (atx- and setex-) " http://daringfireball.net/projects/markdown/syntax#header " @@ -95,7 +95,7 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0) 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 = '' @@ -171,15 +171,27 @@ let b:front_matter = 0 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. diff --git a/test/python-folding.vader b/test/python-folding.vader index 91fc9e2..9196ea6 100644 --- a/test/python-folding.vader +++ b/test/python-folding.vader @@ -21,17 +21,16 @@ This is code block 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; @@ -59,7 +58,7 @@ foobar 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; --- -- 2.39.5