diff --git a/autoload/vimtex/env.vim b/autoload/vimtex/env.vim index 5946f7a..1378e31 100644 --- a/autoload/vimtex/env.vim +++ b/autoload/vimtex/env.vim @@ -119,7 +119,7 @@ endfunction function! vimtex#env#is_inside(env) " {{{1 return searchpair('\\begin\s*{' . a:env . '\*\?}', '', - \ '\\end\s*{' . a:env . '\*\?}', 'bnWm') + \ '\\end\s*{' . a:env . '\*\?}', 'bnW') endfunction " }}}1 diff --git a/indent/tex.vim b/indent/tex.vim index 561e3d6..8543608 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -137,7 +137,8 @@ let s:re_delims = vimtex#delim#get_delim_regexes() " }}}1 function! s:indent_tikz(lnum, prev) " {{{1 - if vimtex#env#is_inside('tikzpicture') + let l:env_lnum = vimtex#env#is_inside('tikzpicture') + if l:env_lnum > 0 && l:env_lnum < a:lnum let l:prev_starts = a:prev =~# s:tikz_commands let l:prev_stops = a:prev =~# ';\s*$' @@ -148,7 +149,7 @@ function! s:indent_tikz(lnum, prev) " {{{1 " Decrease indent on tikz command end, i.e. on semicolon if ! l:prev_starts && l:prev_stops - let l:context = join(getline(max([1,a:lnum-4]), a:lnum-1), '') + let l:context = join(getline(l:env_lnum, a:lnum-1), '') return -&sw*(l:context =~# s:tikz_commands) endif endif diff --git a/test/vader/indentation.vader b/test/vader/indentation.vader index c93f16b..dc677c0 100644 --- a/test/vader/indentation.vader +++ b/test/vader/indentation.vader @@ -130,6 +130,15 @@ Given tex (Indent: tikz): \draw [solid] let \p{O} = (outerContactHead) in (outerContactHead) -- (\x{O},-2.5) node [yshift=-.25cm] {(ii)}; + + \begin{axis} + \addplot + table[row sep=crcr]{% + 0 0\\ + 1 1\\ + 2 2\\ + }; + \end{axis} \end{tikzpicture} Do (Indent): @@ -156,6 +165,15 @@ Expect tex (Verify): \draw [solid] let \p{O} = (outerContactHead) in (outerContactHead) -- (\x{O},-2.5) node [yshift=-.25cm] {(ii)}; + + \begin{axis} + \addplot + table[row sep=crcr]{% + 0 0\\ + 1 1\\ + 2 2\\ + }; + \end{axis} \end{tikzpicture} Given tex (Indent: verbatims):