2016-01-24 17:02:33 -05:00
|
|
|
" vimtex - LaTeX plugin for Vim
|
|
|
|
"
|
|
|
|
" Maintainer: Karl Yngve Lervåg
|
|
|
|
" Email: karl.yngve@gmail.com
|
|
|
|
"
|
|
|
|
|
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
let s:source = {
|
|
|
|
\ 'name' : 'vimtex_toc',
|
|
|
|
\ 'sorters' : 'sorter_nothing',
|
2016-01-24 17:11:39 -05:00
|
|
|
\ 'default_kind' : 'jump_list',
|
2016-01-25 16:25:36 -05:00
|
|
|
\ 'syntax' : 'uniteSource__vimtex',
|
|
|
|
\ 'hooks' : {},
|
2016-01-24 17:02:33 -05:00
|
|
|
\}
|
|
|
|
|
2016-01-24 17:11:39 -05:00
|
|
|
function! s:source.gather_candidates(args, context) " {{{1
|
2016-01-24 17:02:33 -05:00
|
|
|
let entries = vimtex#toc#get_entries()
|
2016-01-25 16:25:36 -05:00
|
|
|
let maxlevel = max(map(copy(entries), 'v:val.level'))
|
|
|
|
|
2016-01-24 17:02:33 -05:00
|
|
|
return map(entries, '{
|
2016-01-25 16:25:36 -05:00
|
|
|
\ "word" : s:format_word(v:val),
|
|
|
|
\ "abbr" : s:format_abbr(v:val, maxlevel - v:val.level),
|
2016-01-24 17:11:39 -05:00
|
|
|
\ "action__path" : v:val.file,
|
|
|
|
\ "action__line" : v:val.line,
|
2016-01-24 17:02:33 -05:00
|
|
|
\ }')
|
|
|
|
endfunction
|
|
|
|
|
2016-01-25 16:25:36 -05:00
|
|
|
" }}}1
|
|
|
|
function! s:source.hooks.on_syntax(args, context) " {{{1
|
|
|
|
syntax match VimtexTocSec0 /0.*/
|
|
|
|
\ contains=VimtexTocLevel,@Tex
|
|
|
|
\ contained containedin=uniteSource__vimtex
|
|
|
|
syntax match VimtexTocSec1 /1.*/
|
|
|
|
\ contains=VimtexTocLevel,@Tex
|
|
|
|
\ contained containedin=uniteSource__vimtex
|
|
|
|
syntax match VimtexTocSec2 /2.*/
|
|
|
|
\ contains=VimtexTocLevel,@Tex
|
|
|
|
\ contained containedin=uniteSource__vimtex
|
|
|
|
syntax match VimtexTocSec3 /3.*/
|
|
|
|
\ contains=VimtexTocLevel,@Tex
|
|
|
|
\ contained containedin=uniteSource__vimtex
|
|
|
|
syntax match VimtexTocSec4 /4.*/
|
|
|
|
\ contains=VimtexTocLevel,@Tex
|
|
|
|
\ contained containedin=uniteSource__vimtex
|
|
|
|
syntax match VimtexTocSecs /[5-9].*/
|
|
|
|
\ contains=VimtexTocLevel,@Tex
|
|
|
|
\ contained containedin=uniteSource__vimtex
|
|
|
|
syntax match VimtexTocLevel
|
|
|
|
\ /\d/ conceal nextgroup=VimtexTocNum
|
|
|
|
\ contained containedin=VimtexTocSec[0-4]
|
|
|
|
syntax match VimtexTocNum
|
|
|
|
\ /\(\([A-Z]\+\>\|\d\+\)\(\.\d\+\)*\)\?\s*/
|
|
|
|
\ contained
|
|
|
|
endfunction
|
|
|
|
|
2016-01-24 17:11:39 -05:00
|
|
|
" }}}1
|
|
|
|
|
2016-01-25 16:25:36 -05:00
|
|
|
function! s:format_word(entry) " {{{1
|
2016-01-24 17:26:49 -05:00
|
|
|
return printf('%-10s%s', s:print_number(a:entry.number), a:entry.title)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" }}}1
|
2016-01-25 16:25:36 -05:00
|
|
|
function! s:format_abbr(entry, level) " {{{1
|
|
|
|
return printf('%1s%-10s%s',
|
|
|
|
\ a:level, s:print_number(a:entry.number), a:entry.title)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" }}}1
|
|
|
|
|
2016-01-24 17:26:49 -05:00
|
|
|
function! s:print_number(number) " {{{1
|
|
|
|
if empty(a:number) | return '' | endif
|
|
|
|
|
|
|
|
let number = [
|
|
|
|
\ a:number.part,
|
|
|
|
\ a:number.chapter,
|
|
|
|
\ a:number.section,
|
|
|
|
\ a:number.subsection,
|
|
|
|
\ a:number.subsubsection,
|
|
|
|
\ a:number.subsubsubsection,
|
|
|
|
\ ]
|
|
|
|
|
|
|
|
" Remove unused parts
|
|
|
|
while number[0] == 0
|
|
|
|
call remove(number, 0)
|
|
|
|
endwhile
|
|
|
|
while number[-1] == 0
|
|
|
|
call remove(number, -1)
|
|
|
|
endwhile
|
|
|
|
|
2016-01-25 16:25:36 -05:00
|
|
|
if a:number.frontmatter || a:number.backmatter
|
|
|
|
return ''
|
|
|
|
elseif a:number.appendix
|
|
|
|
let number[0] = nr2char(number[0] + 64)
|
|
|
|
endif
|
|
|
|
|
2016-01-24 17:26:49 -05:00
|
|
|
return join(number, '.')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" }}}1
|
|
|
|
|
2016-01-24 17:02:33 -05:00
|
|
|
function! unite#sources#vimtex_toc#define()
|
|
|
|
return s:source
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|