Fixed bug where toc did not find input file
This commit is contained in:
parent
c6fe12f646
commit
4d73dfda98
@ -23,9 +23,9 @@ setlocal tabstop=8
|
|||||||
setlocal cole=0
|
setlocal cole=0
|
||||||
setlocal cocu=nvic
|
setlocal cocu=nvic
|
||||||
if g:latex_toc_fold
|
if g:latex_toc_fold
|
||||||
setlocal foldmethod=expr
|
setlocal foldmethod=expr
|
||||||
setlocal foldexpr=toc#fold(v:lnum)
|
setlocal foldexpr=toc#fold(v:lnum)
|
||||||
setlocal foldtext=toc#fold_tex()
|
setlocal foldtext=toc#fold_tex()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Define mappings
|
" Define mappings
|
||||||
@ -44,90 +44,114 @@ nnoremap <buffer> <silent> <2-leftmouse> :call <SID>toc_activate(1)<cr>
|
|||||||
|
|
||||||
" {{{1 s:toc_activate
|
" {{{1 s:toc_activate
|
||||||
function! s:toc_activate(close)
|
function! s:toc_activate(close)
|
||||||
let n = getpos('.')[1] - 1
|
let n = getpos('.')[1] - 1
|
||||||
|
|
||||||
if n >= len(b:toc)
|
if n >= len(b:toc)
|
||||||
return
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let entry = b:toc[n]
|
||||||
|
|
||||||
|
let titlestr = s:toc_escape_title(entry['text'])
|
||||||
|
|
||||||
|
" Search for duplicates
|
||||||
|
let i=0
|
||||||
|
let entry_hash = entry['level'].titlestr
|
||||||
|
let duplicates = 0
|
||||||
|
while i<n
|
||||||
|
let i_hash = b:toc[i]['level'].s:toc_escape_title(b:toc[i]['text'])
|
||||||
|
if i_hash == entry_hash
|
||||||
|
let duplicates += 1
|
||||||
endif
|
endif
|
||||||
|
let i += 1
|
||||||
|
endwhile
|
||||||
|
let toc_bnr = bufnr('%')
|
||||||
|
let toc_wnr = winnr()
|
||||||
|
|
||||||
let entry = b:toc[n]
|
execute b:calling_win . 'wincmd w'
|
||||||
|
|
||||||
let titlestr = s:toc_escape_title(entry['text'])
|
let files = [entry['file']]
|
||||||
|
for line in filter(readfile(entry['file']), 'v:val =~ ''\\input{''')
|
||||||
|
call add(files, matchstr(line, '{\zs.*\ze\(\.tex\)\?}') . '.tex')
|
||||||
|
endfor
|
||||||
|
|
||||||
" Search for duplicates
|
" Find section in buffer (or inputted files)
|
||||||
"
|
call s:toc_find_match('\\' . entry['level'] . '\_\s*{' . titlestr . '}',
|
||||||
let i=0
|
\ duplicates, files)
|
||||||
let entry_hash = entry['level'].titlestr
|
|
||||||
let duplicates = 0
|
|
||||||
while i<n
|
|
||||||
let i_entry = b:toc[n]
|
|
||||||
let i_hash = b:toc[i]['level'].s:toc_escape_title(b:toc[i]['text'])
|
|
||||||
if i_hash == entry_hash
|
|
||||||
let duplicates += 1
|
|
||||||
endif
|
|
||||||
let i += 1
|
|
||||||
endwhile
|
|
||||||
let toc_bnr = bufnr('%')
|
|
||||||
let toc_wnr = winnr()
|
|
||||||
|
|
||||||
execute b:calling_win . 'wincmd w'
|
if a:close
|
||||||
|
if g:latex_toc_resize
|
||||||
let bnr = bufnr(entry['file'])
|
silent exe "set columns-=" . g:latex_toc_width
|
||||||
if bnr == -1
|
|
||||||
execute 'badd ' . entry['file']
|
|
||||||
let bnr = bufnr(entry['file'])
|
|
||||||
endif
|
|
||||||
|
|
||||||
execute 'buffer! ' . bnr
|
|
||||||
|
|
||||||
" skip duplicates
|
|
||||||
while duplicates > 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:latex_toc_resize
|
|
||||||
silent exe "set columns-=" . g:latex_toc_width
|
|
||||||
endif
|
|
||||||
execute 'bwipeout ' . toc_bnr
|
|
||||||
else
|
|
||||||
execute toc_wnr . 'wincmd w'
|
|
||||||
endif
|
endif
|
||||||
|
execute 'bwipeout ' . toc_bnr
|
||||||
|
else
|
||||||
|
execute toc_wnr . 'wincmd w'
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" {{{1 s:toc_close
|
" {{{1 s:toc_close
|
||||||
function! s:toc_close()
|
function! s:toc_close()
|
||||||
if g:latex_toc_resize
|
if g:latex_toc_resize
|
||||||
silent exe "set columns-=" . g:latex_toc_width
|
silent exe "set columns-=" . g:latex_toc_width
|
||||||
endif
|
endif
|
||||||
bwipeout
|
bwipeout
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" {{{1 s:toc_escape_title
|
" {{{1 s:toc_escape_title
|
||||||
function! s:toc_escape_title(titlestr)
|
function! s:toc_escape_title(titlestr)
|
||||||
" Credit goes to Marcin Szamotulski for the following fix. It allows to
|
" Credit goes to Marcin Szamotulski for the following fix. It allows to
|
||||||
" match through commands added by TeX.
|
" match through commands added by TeX.
|
||||||
|
|
||||||
|
let titlestr = substitute(a:titlestr, '\\\w*\>\s*\%({[^}]*}\)\?', '.*', 'g')
|
||||||
|
let titlestr = escape(titlestr, '\')
|
||||||
|
return substitute(titlestr, ' ', '\\_\\s\\+', 'g')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" {{{1 s:toc_find_match
|
||||||
|
function! s:toc_find_match(strsearch,duplicates,files)
|
||||||
|
|
||||||
|
call s:toc_open_buf(a:files[0])
|
||||||
|
let dups = a:duplicates
|
||||||
|
|
||||||
|
" Skip duplicates
|
||||||
|
while dups > 0
|
||||||
|
if search(a:strsearch, 'w')
|
||||||
|
let dups -= 1
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if search(a:strsearch, 'w')
|
||||||
|
normal! zv
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
call s:toc_find_match(a:strsearch,dups,a:files[1:])
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" {{{1 s:toc_open_buf
|
||||||
|
function! s:toc_open_buf(file)
|
||||||
|
|
||||||
|
let bnr = bufnr(a:file)
|
||||||
|
if bnr == -1
|
||||||
|
execute 'badd ' . a:file
|
||||||
|
let bnr = bufnr(a:file)
|
||||||
|
endif
|
||||||
|
execute 'buffer! ' . bnr
|
||||||
|
|
||||||
let titlestr = substitute(a:titlestr, '\\\w*\>\s*\%({[^}]*}\)\?', '.*', 'g')
|
|
||||||
let titlestr = escape(titlestr, '\')
|
|
||||||
return substitute(titlestr, ' ', '\\_\\s\\+', 'g')
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" {{{1 s:toc_toggle_numbers
|
" {{{1 s:toc_toggle_numbers
|
||||||
function! s:toc_toggle_numbers()
|
function! s:toc_toggle_numbers()
|
||||||
if b:toc_numbers
|
if b:toc_numbers
|
||||||
setlocal conceallevel=3
|
setlocal conceallevel=3
|
||||||
let b:toc_numbers = 0
|
let b:toc_numbers = 0
|
||||||
else
|
else
|
||||||
setlocal conceallevel=0
|
setlocal conceallevel=0
|
||||||
let b:toc_numbers = 1
|
let b:toc_numbers = 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user