File: beamer_frame.vim

package info (click to toggle)
vim-vimtex 2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,844 kB
  • sloc: makefile: 360; python: 103
file content (89 lines) | stat: -rw-r--r-- 2,331 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email:      karl.yngve@gmail.com
"

function! vimtex#parser#toc#beamer_frame#new() abort " {{{1
  return s:matcher
endfunction

" }}}1

let s:matcher = {
      \ 'prefilter_cmds': ['begin'],
      \ 'priority': 0,
      \ 're': '^\s*\\begin{frame}',
      \ 're_end': '^\s*\\end{frame}',
      \ 're_match': '^\s*\\begin{frame}\%(\[[^]]\+\]\)\?{\zs.*\ze}\s*$',
      \}
function! s:matcher.init() abort dict " {{{1
  let self.number = 0
  let self.title = ''
  let self.subtitle = ''
endfunction

" }}}1
function! s:matcher.get_entry(context) abort dict " {{{1
  let self.number += 1
  let self.title = ''
  let self.subtitle = ''

  " Handle subtitles, e.g. \begin{frame}{title}{subtitle}
  let l:parts = split(matchstr(a:context.line, self.re_match), '}\s*{')
  if len(l:parts) > 1
    let self.title = trim(l:parts[0])
    let self.subtitle = trim(l:parts[1])
  elseif len(l:parts) > 0
    let self.title = trim(l:parts[0])
  endif

  if empty(self.title)
    let a:context.continue = 'beamer_frame'
  endif

  return {
        \ 'title'  : self.get_title(),
        \ 'number' : '',
        \ 'file'   : a:context.file,
        \ 'line'   : a:context.lnum,
        \ 'level'  : a:context.max_level - a:context.level.current,
        \ 'rank'   : a:context.lnum_total,
        \ 'type'   : 'content',
        \ }
endfunction

" }}}1
function! s:matcher.get_title() abort dict " {{{1
  if !empty(self.title) && !empty(self.subtitle)
    let l:title = ': ' . self.title . ' - ' . self.subtitle
  elseif !empty(self.title)
    let l:title = ': ' . self.title
  elseif !empty(self.subtitle)
    let l:title = ': ' . self.subtitle
  else
    let l:title = ''
  endif

  return printf("Frame %d%s", self.number, l:title)
endfunction

" }}}1
function! s:matcher.continue(context) abort dict " {{{1
  if empty(self.title)
    let self.title = trim(
          \ matchstr(a:context.line, '^\s*\\frametitle\s*{\zs[^}]*'))
  endif
  if empty(self.subtitle)
    let self.subtitle = trim(
          \ matchstr(a:context.line, '^\s*\\framesubtitle\s*{\zs[^}]*'))
  endif

  if (!empty(self.title) && !empty(self.subtitle))
        \ || a:context.line =~# self.re_end
    let a:context.entry.title = self.get_title()
    unlet! a:context.continue
  endif
endfunction

" }}}1