From fa66acf7fd03c70eced46f985e33011ef133de9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 20 Jul 2014 15:51:13 +0200 Subject: [PATCH] Fixed folding of TOC window (fixes #34) --- autoload/toc.vim | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/autoload/toc.vim b/autoload/toc.vim index 4dc720f..0c51d8d 100644 --- a/autoload/toc.vim +++ b/autoload/toc.vim @@ -1,37 +1,29 @@ function! toc#fold_level(lnum) " {{{1 - let line = getline(a:lnum) - let match_s1 = line =~# '^\w\+\s' - let match_s2 = line =~# '^\w\+\.\w\+\s' - let match_s3 = line =~# '^\w\+\.\w\+\.\w\+\s' + let pline = getline(a:lnum - 1) + let cline = getline(a:lnum) + let nline = getline(a:lnum + 1) + let pn = matchstr(pline, '\d$') + let cn = matchstr(cline, '\d$') + let nn = matchstr(nline, '\d$') - if g:latex_toc_fold_levels >= 3 - if match_s3 - return ">3" - endif - endif + " Don't fold options + if cline =~# '^\s*$' + return 0 + endif - if g:latex_toc_fold_levels >= 2 - if match_s2 - return ">2" - endif - endif + if nn > cn + return '>' . nn + endif - if match_s1 - return ">1" - endif + if cn < pn && cn >= nn + return cn + endif - " Don't fold options - if line =~# '^\s*$' - return 0 - endif - - " Return previous fold level - return "=" + return '=' endfunction function! toc#fold_text() " {{{1 - let parts = matchlist(getline(v:foldstart), '^\(.*\)\t\(.*\)$') - return printf('%-8s%-72s', parts[1], parts[2]) + return getline(v:foldstart) endfunction " }}}1