# HG changeset patch # User Steve Losh # Date 1402920021 14400 # Node ID 1de6d9ecd3507516c548cb362baaceab655fc430 # Parent 4e6f3d36c2417fd778f30192b90c51795bdcd368 fuckoing markdown i had a nice commit message here but vim ate it. fuck it. diff -r 4e6f3d36c241 -r 1de6d9ecd350 vim/after/ftplugin/markdown.vim --- a/vim/after/ftplugin/markdown.vim Mon Jun 02 11:39:16 2014 -0700 +++ b/vim/after/ftplugin/markdown.vim Mon Jun 16 08:00:21 2014 -0400 @@ -4,25 +4,51 @@ " this code can be placed in file " $HOME/.vim/after/ftplugin/markdown.vim -func! Foldexpr_markdown(lnum) +function! Get_Markdown_Header_Level(lnum) " {{{ let l1 = getline(a:lnum) if l1 =~ '^\s*$' - " ignore empty lines - return '=' + " a blank line is never a header + return 0 endif let l2 = getline(a:lnum+1) if l2 =~ '^==\+\s*' " next line is underlined (level 1) - return '>1' + return 1 elseif l2 =~ '^--\+\s*' " next line is underlined (level 2) - return '>2' + return 2 elseif l1 =~ '^#' " current line starts with hashes - return '>'.matchend(l1, '^#\+') + return matchend(l1, '^#\+') + endif + + return 0 +endfunction " }}} + +function! Foldexpr_markdown(lnum) " {{{ + let line = getline(a:lnum) + let anchor_re = '\v^\' . next_line_hval + else + return '=' + endif + endif + + let line_hval = Get_Markdown_Header_Level(a:lnum) + + if line_hval + if getline(a:lnum - 1) =~ anchor_re + return line_hval + else + return '>' . line_hval + endif elseif a:lnum == 1 " fold any 'preamble' return '>1' @@ -30,8 +56,30 @@ " keep previous foldlevel return '=' endif -endfunc +endfunction " }}} + +function! MarkdownFoldText() " {{{ + let line = getline(v:foldstart) + + let anchor_re = '\v^\