Sometimes doesn't unindent with a \end
Brought to you by:
srinathava,
tmaas
For a file like
\begin{test}
foo\end{test}
bar
After the indent, it should be like
\begin{test}
foo\end{test}
bar
But when I use the automatic indent, it becomes
\begin{ŧest}
foo\end{test}
bar
After some experiment, I found out that \end were ignored every time there is other things that spaces and tabs before them on the line.
Looking at the source code of the file indent/tex.vim, I found that it was about the line 180 that reads
if cline =~ '^\s*\\end' && cline !~ g:tex_noindent_env
I changed it on my computer to
if cline =~ '^\s*\\end' && cline !~ g:tex_noindent_env
And it fixed the bug
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Ok, my fix doesn't work, I know understand why the '^\s*' was there but I have another fix.
I watch the previous line. If it contains a '\\end' and no '\\end' starting a line, it unindent.
here is the change
" Subtract a 'shiftwidth' when an environment ends
if cline =~ '^\s*\\end' && cline !~ 'verbatim'
\&& cline !~ 'document'
\&& cline !~ 'comment'
if g:tex_indent_items == 1
" Remove another sw for item-environments
if cline =~ 'itemize\|description\|enumerate\|thebibliography'
let ind = ind - &sw
endif
endif
let ind = ind - &sw
endif
+" Subtract a 'shiftwidth' when an environment ended
+" the previous line but the shifwidth wasn't
+" applied because it didn't begin the line
+if line =~ '\\end' && line !~ '^\s*\\end'
+ \&& line !~ 'verbatim'
+ \&& line !~ 'document'
+ \&& line !~ 'comment'
+
+ if g:tex_indent_items == 1
+ " Remove another sw for item-environments
+ if line =~ 'itemize\|description\|enumerate\|thebibliography'
+ let ind = ind - &sw
+ endif
+ endif
+
+ let ind = ind - &sw
+endif
" Special treatment for 'item'
" ----------------------------
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"