]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Pythonic folding expand level 1 by default
authorHiroshi Shirosaki <h.shirosaki@gmail.com>
Wed, 5 Jun 2019 05:52:34 +0000 (14:52 +0900)
committerHiroshi Shirosaki <h.shirosaki@gmail.com>
Wed, 5 Jun 2019 07:12:29 +0000 (16:12 +0900)
Fix test failures.
Change document of Pythonic folding.

README.md
after/ftplugin/markdown.vim
test/python-folding.vader

index 6695b06ac74f62d5d312f55bbb22083f22fe0e94..fd3be68762df7eb7c81fb72bcbe5a2270548142a 100644 (file)
--- 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`
 
index 89d1c38847c2f27ec0e6ed80ac4e2ac3f3658fbb..8be6ff918be1c33aca7912f17a1384b86254cea7 100644 (file)
@@ -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.
index 91fc9e270eabf6d12d88ebdc97e1440eaf0330f9..9196ea601de102e613655e40c9c3a1faac4d43cb 100644 (file)
@@ -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;
 ---