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.
1 " folding for Markdown headers, both styles (atx- and setex-)
2 " http://daringfireball.net/projects/markdown/syntax#header
4 " this code can be placed in file
5 " $HOME/.vim/after/ftplugin/markdown.vim
7 " original version from Steve Losh's gist: https://gist.github.com/1038710
9 func! s:is_mkdCode(lnum)
10 return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode'
13 func! s:effective_line(lnum)
14 let line = getline(a:lnum)
15 return (line !~ '^[=-#]' || s:is_mkdCode(a:lnum)) ? '' : line
18 if get(g:, "vim_markdown_folding_style_pythonic", 0)
19 func! Foldexpr_markdown(lnum)
20 let l2 = s:effective_line(a:lnum+1)
22 " next line is underlined (level 1)
24 elseif l2 =~ '^--\+\s*'
25 " next line is underlined (level 2)
29 let l1 = s:effective_line(a:lnum)
31 " current line starts with hashes
32 return '>'.(matchend(l1, '^#\+') - 1)
37 " keep previous foldlevel
42 fun! Foldtext_markdown()
43 let line = getline(v:foldstart)
44 let has_numbers = &number || &relativenumber
45 let nucolwidth = &fdc + has_numbers * &numberwidth
46 let windowwidth = winwidth(0) - nucolwidth - 6
47 let foldedlinecount = v:foldend - v:foldstart
48 let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
49 let line = substitute(line, '\%("""\|''''''\)', '', '')
50 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1
51 return line . ' ' . repeat("-", fillcharcount) . ' ' . foldedlinecount
54 func! Foldexpr_markdown(lnum)
55 let l2 = s:effective_line(a:lnum+1)
57 " next line is underlined (level 1)
59 elseif l2 =~ '^--\+\s*'
60 " next line is underlined (level 2)
64 let l1 = s:effective_line(a:lnum)
66 " don't include the section title in the fold
73 let l0 = s:effective_line(a:lnum-1)
76 " current line starts with hashes
77 return '>'.matchend(l0, '^#\+')
79 " keep previous foldlevel
85 if !get(g:, "vim_markdown_folding_disabled", 0)
86 setlocal foldexpr=Foldexpr_markdown(v:lnum)
87 setlocal foldmethod=expr
88 if get(g:, "vim_markdown_folding_style_pythonic", 0)
89 setlocal foldtext=Foldtext_markdown()