" {{{1 Settings setlocal buftype=nofile setlocal bufhidden=wipe setlocal nobuflisted setlocal noswapfile setlocal nowrap setlocal nospell setlocal cursorline setlocal nonumber setlocal nolist setlocal tabstop=8 setlocal cole=0 setlocal cocu=nvic if g:LatexBox_fold_toc setlocal foldmethod=expr setlocal foldexpr=TOCFoldLevel(v:lnum) setlocal foldtext=TOCFoldText() endif " }}}1 " {{{1 Functions " {{{2 TOCClose function! s:TOCClose() if g:LatexBox_split_resize silent exe "set columns-=" . g:LatexBox_split_width endif bwipeout endfunction " {{{2 TOCToggleNumbers function! s:TOCToggleNumbers() if b:toc_numbers setlocal conceallevel=3 let b:toc_numbers = 0 else setlocal conceallevel=0 let b:toc_numbers = 1 endif endfunction " {{{2 EscapeTitle function! s:EscapeTitle(titlestr) " Credit goes to Marcin Szamotulski for the following fix. It allows to " match through commands added by TeX. let titlestr = substitute(a:titlestr, '\\\w*\>\s*\%({[^}]*}\)\?', '.*', 'g') let titlestr = escape(titlestr, '\') let titlestr = substitute(titlestr, ' ', '\\_\\s\\+', 'g') return titlestr endfunction " {{{2 TOCActivate function! s:TOCActivate(close) let n = getpos('.')[1] - 1 if n >= len(b:toc) return endif let entry = b:toc[n] let titlestr = s:EscapeTitle(entry['text']) " Search for duplicates " let i=0 let entry_hash = entry['level'].titlestr let duplicates = 0 while i 0 if search('\\' . entry['level'] . '\_\s*{' . titlestr . '}', 'ws') let duplicates -= 1 endif endwhile if search('\\' . entry['level'] . '\_\s*{' . titlestr . '}', 'ws') normal zv endif if a:close if g:LatexBox_split_resize silent exe "set columns-=" . g:LatexBox_split_width endif execute 'bwipeout ' . toc_bnr else execute toc_wnr . 'wincmd w' endif endfunction " {{{2 TOCFoldLevel function! TOCFoldLevel(lnum) 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' if g:LatexBox_fold_toc_levels >= 3 if match_s3 return ">3" endif endif if g:LatexBox_fold_toc_levels >= 2 if match_s2 return ">2" endif endif if match_s1 return ">1" endif " Don't fold options if line =~# '^\s*$' return 0 endif " Return previous fold level return "=" endfunction " {{{2 TOCFoldText function! TOCFoldText() let parts = matchlist(getline(v:foldstart), '^\(.*\)\t\(.*\)$') return printf('%-8s%-72s', parts[1], parts[2]) endfunction " }}}1 " {{{1 Mappings nnoremap s :call TOCToggleNumbers() nnoremap q :call TOCClose() nnoremap :call TOCClose() nnoremap :call TOCActivate(0) nnoremap :call TOCActivate(1) nnoremap :call TOCActivate(0) nnoremap <2-leftmouse> :call TOCActivate(1) nnoremap G G4k nnoremap OA k nnoremap OB j nnoremap OC l nnoremap OD h " }}}1 " vim:fdm=marker:ff=unix:et:ts=4:sw=4