Only indent tikz if tikz is loaded

This commit is contained in:
Karl Yngve Lervåg 2017-01-10 23:14:06 +01:00
parent a5d006513f
commit 3e63a12448
3 changed files with 15 additions and 3 deletions

View File

@ -485,8 +485,17 @@ endfunction
" }}}1 " }}}1
function! s:init_local_options() " {{{1 function! s:init_local_options() " {{{1
let b:vimtex.sources = [] let b:vimtex.packages = {}
for l:line in vimtex#parser#tex(b:vimtex.tex, {
\ 'detailed' : 0,
\ 're_stop' : '\\begin\s*{document}',
\})
if l:line =~# '\\usepackage.*{tikz}'
let b:vimtex.packages.tikz = 1
endif
endfor
let b:vimtex.sources = []
for [l:file, l:lnum, l:line] in vimtex#parser#tex(b:vimtex.tex) for [l:file, l:lnum, l:line] in vimtex#parser#tex(b:vimtex.tex)
let l:cand = substitute(l:file, '\M' . b:vimtex.root, '', '') let l:cand = substitute(l:file, '\M' . b:vimtex.root, '', '')
if l:cand[0] ==# '/' | let l:cand = l:cand[1:] | endif if l:cand[0] ==# '/' | let l:cand = l:cand[1:] | endif

View File

@ -138,6 +138,8 @@ let s:re_delims = vimtex#delim#get_delim_regexes()
" }}}1 " }}}1
function! s:indent_tikz(lnum, prev) " {{{1 function! s:indent_tikz(lnum, prev) " {{{1
if !has_key(b:vimtex.packages, 'tikz') | return 0 | endif
let l:env_lnum = vimtex#env#is_inside('tikzpicture') let l:env_lnum = vimtex#env#is_inside('tikzpicture')
if l:env_lnum > 0 && l:env_lnum < a:lnum if l:env_lnum > 0 && l:env_lnum < a:lnum
let l:prev_starts = a:prev =~# s:tikz_commands let l:prev_starts = a:prev =~# s:tikz_commands

View File

@ -141,8 +141,9 @@ Given tex (Indent: tikz):
\end{axis} \end{axis}
\end{tikzpicture} \end{tikzpicture}
Do (Indent): Execute (Indent):
gg=G let b:vimtex.packages.tikz = 1
normal gg=G
Expect tex (Verify): Expect tex (Verify):
\tikz \fill[green] rectangle (0.5,0.5); Something \tikz \fill[green] rectangle (0.5,0.5); Something