Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions autoload/vimtex/fold/envs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,20 @@ function! s:folder.parse_caption_frame(line) abort dict " {{{1
let i = v:foldstart
while i <= v:foldend
if getline(i) =~# '^\s*\\frametitle'
return matchstr(getline(i),
let frametitle = matchstr(getline(i),
\ '^\s*\\frametitle\(\[.*\]\)\?{\zs.\{-1,}\ze\(}\s*\)\?$')
if i+1 <= v:foldend && getline(i+1) =~# '^\s*\\framesubtitle'
let framesubtitle = matchstr(getline(i+1),
\ '^\s*\\framesubtitle\(\[.*\]\)\?{\zs.\{-1,}\ze\(}\s*\)\?$')
return printf('%S: %S', frametitle, framesubtitle)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simplify this to:

let frametitle .= ': ' . matchstr(getline(i+1),
      \ '^.*\\framesubtitle\(\[.*\]\)\?{\zs.\{-1,}\ze\(}\s*\)\?$')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this and as far as I can tell this adds : 0 to the fold text if no subtitle is available, so the if condition seems necessary. But I could remove the extra variable and return statement, if you prefer.

end
return frametitle
end
let i += 1
endwhile

" If no caption found, check for a caption comment
return matchstr(a:line,'\\begin\*\?{.*}\s*%\s*\zs.*')
return matchstr(a:line,'\\begin\*\?{.*}\(\[.*\]\)\?\s*%\s*\zs.*')
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change \(\[.*\]\)\? to \(\[[^\]]*\]\)\?.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get it to work with the suggestion. What would be the improvement? I copied the regex for detecting the brackets from the \frametitle regex a few lines above this.

endfunction

" }}}1
13 changes: 13 additions & 0 deletions test/test-folding/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,17 @@ \section{test 3}
\end{proof}
\end{enumerate}

% The frames need to be in this order for the test to pass. This is likely a
% bug in vim, see https://github.com/lervag/vimtex/pull/1830#issuecomment-775527621
\begin{frame}
\frametitle{Title}
\framesubtitle{Subtitle}

hello world
\end{frame}

\begin{frame}[noframenumbering] % Title page
hello world
\end{frame}

\end{document}
9 changes: 9 additions & 0 deletions test/test-folding/test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ call vimtex#test#assert_equal(3, foldlevel(186))
call vimtex#test#assert_equal(1, foldlevel(190))
call vimtex#test#assert_equal(2, foldlevel(202))

call vimtex#test#assert_equal(2, foldlevel(206))
call vimtex#test#assert_equal(
\ '\begin{frame} Title: Subtitle',
\ foldtextresult(206))
call vimtex#test#assert_equal(2, foldlevel(213))
call vimtex#test#assert_equal(
\ '\begin{frame} Title page',
\ foldtextresult(213))

call vimtex#test#assert_equal(1, foldlevel(line('$')-1))

quit!
Expand Down