X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/d80bf38f92fdd2516b1a2d5576c2a8089453d73b..16c6a73e6c0af28a3aa356cc5a84ead2fb563d64:/after/ftplugin/markdown.vim?ds=sidebyside diff --git a/after/ftplugin/markdown.vim b/after/ftplugin/markdown.vim index 94267ee..a140c25 100644 --- a/after/ftplugin/markdown.vim +++ b/after/ftplugin/markdown.vim @@ -11,30 +11,32 @@ func! s:is_mkdCode(lnum) endfunc func! s:effective_line(lnum) - return s:is_mkdCode(a:lnum) ? '' : getline(a:lnum) + let line = getline(a:lnum) + return (line !~ '^[=-#]' || s:is_mkdCode(a:lnum)) ? '' : line endfunc func! Foldexpr_markdown(lnum) - if (a:lnum == 1) - let l0 = '' - else - let l0 = s:effective_line(a:lnum-1) - endif - - let l1 = s:effective_line(a:lnum) - let l2 = s:effective_line(a:lnum+1) - if l2 =~ '^==\+\s*' " next line is underlined (level 1) return '>1' elseif l2 =~ '^--\+\s*' " next line is underlined (level 2) return '>2' - elseif l1 =~ '^#' + endif + + let l1 = s:effective_line(a:lnum) + if l1 =~ '^#' " don't include the section title in the fold return '-1' - elseif l0 =~ '^#' + endif + + if (a:lnum == 1) + let l0 = '' + else + let l0 = s:effective_line(a:lnum-1) + endif + if l0 =~ '^#' " current line starts with hashes return '>'.matchend(l0, '^#\+') else