From 4cbdfc4fcc18e3e178afc33e52f2dfef481bdae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Tue, 24 Mar 2015 14:20:52 +0100 Subject: [PATCH] Excl preamble inputs in ToC and ToL (fixes #138) --- autoload/vimtex/labels.vim | 10 ++++++++-- autoload/vimtex/toc.vim | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/autoload/vimtex/labels.vim b/autoload/vimtex/labels.vim index ebb7f69..0dfef3d 100644 --- a/autoload/vimtex/labels.vim +++ b/autoload/vimtex/labels.vim @@ -24,6 +24,8 @@ endfunction function! vimtex#labels#open() " {{{1 if vimtex#index#open(s:name) | return | endif + let s:preamble = 1 + let index = {} let index.name = s:name let index.entries = s:gather_labels(g:vimtex#data[b:vimtex.id].tex) @@ -92,6 +94,7 @@ endfunction " {{{1 TOL variables +let s:preamble = 1 let s:re_input = '\v^\s*\\%(input|include)\s*\{' let s:re_input_file = s:re_input . '\zs[^\}]+\ze}' let s:re_label = '\v\\label\{' @@ -105,8 +108,11 @@ function! s:gather_labels(file) " {{{1 for line in readfile(a:file) let lnum += 1 - " 1. Parse inputs or includes - if line =~# s:re_input + if line =~# '\v^\s*\\begin\{document\}' + let s:preamble = 0 + endif + + if line =~# s:re_input && !s:preamble call extend(tac, s:gather_labels(s:gather_labels_input(line, a:file))) continue endif diff --git a/autoload/vimtex/toc.vim b/autoload/vimtex/toc.vim index 86fef24..e5712cc 100644 --- a/autoload/vimtex/toc.vim +++ b/autoload/vimtex/toc.vim @@ -351,7 +351,7 @@ function! s:parse_file(file) " {{{1 let lnum += 1 " 1. Parse inputs or includes - if line =~# s:re_input + if line =~# s:re_input && !s:number.preamble call extend(toc, s:parse_file(s:parse_line_input(line, a:file))) continue endif