From 9ee94751e751d6c0dbfcd1845f43d5f4b6fb71ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sat, 1 Oct 2016 19:41:37 +0200 Subject: [PATCH] Fix #572: Better parsing of sectioning titles --- autoload/vimtex/fold.vim | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/autoload/vimtex/fold.vim b/autoload/vimtex/fold.vim index bf2d062..97aa482 100644 --- a/autoload/vimtex/fold.vim +++ b/autoload/vimtex/fold.vim @@ -302,14 +302,10 @@ function! vimtex#fold#text() " {{{1 let title = 'Backmatter' elseif line =~# '\\appendix' let title = 'Appendix' - elseif line =~# secpat1 . '.*\}' - let title = matchstr(line, secpat1 . '\zs.*\ze}') elseif line =~# secpat1 - let title = matchstr(line, secpat1 . '\zs.*') - elseif line =~# secpat2 . '.*\]' - let title = matchstr(line, secpat2 . '\zs.*\ze\]') + let title = s:parse_sec_title(matchstr(line, secpat1 . '\zs.*'), 0) elseif line =~# secpat2 - let title = matchstr(line, secpat2 . '\zs.*') + let title = s:parse_sec_title(matchstr(line, secpat2 . '\zs.*'), 1) elseif line =~# '\vFake' . sections let title = matchstr(line, '\vFake' . sections . '.*') elseif line =~# '^\s*%' @@ -424,6 +420,24 @@ function! s:parse_caption_frame(line) " {{{2 endif endfunction +" }}}2 +function! s:parse_sec_title(string, type) " {{{2 + let l:idx = 0 + let l:length = strlen(a:string) + let l:level = 1 + while l:level >= 1 + let l:idx += 1 + if l:idx > l:length + break + elseif a:string[l:idx] ==# ['}',']'][a:type] + let l:level -= 1 + elseif a:string[l:idx] ==# ['{','['][a:type] + let l:level += 1 + endif + endwhile + return strpart(a:string, 0, l:idx) +endfunction + " }}}2 " }}}1