Fixed #559: Strange indentation due to ampersands

This commit is contained in:
Karl Yngve Lervåg 2016-09-17 19:54:39 +02:00
parent 4ba99f83bd
commit ec6000815f
2 changed files with 44 additions and 7 deletions

View File

@ -44,7 +44,7 @@ function! VimtexIndent(lnum) " {{{1
return indent(a:lnum)
endif
let l:nprev = s:get_prev_line(l:nprev, 'ignore-ampersands')
let l:nprev = s:get_prev_line(l:nprev)
if l:nprev == 0 | return 0 | endif
let l:prev = getline(l:nprev)
@ -56,16 +56,12 @@ function! VimtexIndent(lnum) " {{{1
endfunction
"}}}
function! s:get_prev_line(lnum, ...) " {{{1
let l:ignore_amps = a:0 > 0
function! s:get_prev_line(lnum) " {{{1
let l:lnum = a:lnum
let l:prev = getline(l:lnum)
while l:lnum != 0
\ && (l:prev =~# '^\s*%'
\ || s:is_verbatim(l:prev, l:lnum)
\ || match(l:prev, '\\\@<!&') >= 0)
\ && (l:prev =~# '^\s*%' || s:is_verbatim(l:prev, l:lnum))
let l:lnum = prevnonblank(l:lnum - 1)
let l:prev = getline(l:lnum)
endwhile

View File

@ -172,3 +172,44 @@ Expect tex (Verify):
not affect verbatim environments!
\end{lstlisting}
Given tex (Indent: With ampersands):
\begin{tabular}{cc}
\begin{tabular}{c}
Cell 1
\end{tabular} &
\begin{tabular}{c}
Cell 2
\end{tabular}
\end{tabular}
\begin{equation}
\begin{aligned}
& \left(
\begin{bmatrix}
123
\end{bmatrix} \right)
\end{aligned}
\end{equation}
Do (Indent):
gg=G
Expect tex (Verify):
\begin{tabular}{cc}
\begin{tabular}{c}
Cell 1
\end{tabular} &
\begin{tabular}{c}
Cell 2
\end{tabular}
\end{tabular}
\begin{equation}
\begin{aligned}
& \left(
\begin{bmatrix}
123
\end{bmatrix} \right)
\end{aligned}
\end{equation}