Fix #634: Add option to ignore indents on envs
This commit is contained in:
parent
6a08af94a4
commit
7d740682d6
@ -590,6 +590,11 @@ Options~
|
|||||||
|
|
||||||
Default value: 1
|
Default value: 1
|
||||||
|
|
||||||
|
*g:vimtex_indent_ignored_envs*
|
||||||
|
List of environments that should not add/reduce indentation.
|
||||||
|
|
||||||
|
Default value: ['document']
|
||||||
|
|
||||||
*g:vimtex_index_resize*
|
*g:vimtex_index_resize*
|
||||||
Whether or not to automatically resize vim when index windows are opened.
|
Whether or not to automatically resize vim when index windows are opened.
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ let b:did_vimtex_indent = 1
|
|||||||
|
|
||||||
call vimtex#util#set_default('g:vimtex_indent_enabled', 1)
|
call vimtex#util#set_default('g:vimtex_indent_enabled', 1)
|
||||||
if !g:vimtex_indent_enabled | finish | endif
|
if !g:vimtex_indent_enabled | finish | endif
|
||||||
|
call vimtex#util#set_default('g:vimtex_indent_ignored_envs', [
|
||||||
|
\ 'document',
|
||||||
|
\])
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
@ -87,8 +90,8 @@ function! s:indent_envs(cur, prev) " {{{1
|
|||||||
let l:ind = 0
|
let l:ind = 0
|
||||||
|
|
||||||
" First for general environments
|
" First for general environments
|
||||||
let l:ind += &sw*((a:prev =~# '\\begin{.*}') && (a:prev !~# 'document'))
|
let l:ind += &sw*((a:prev =~# '\\begin{.*}') && (a:prev !~# s:envs_ignored))
|
||||||
let l:ind -= &sw*((a:cur =~# '\\end{.*}') && (a:cur !~# 'document'))
|
let l:ind -= &sw*((a:cur =~# '\\end{.*}') && (a:cur !~# s:envs_ignored))
|
||||||
|
|
||||||
" Indentation for prolonged items in lists
|
" Indentation for prolonged items in lists
|
||||||
let l:ind += &sw*((a:prev =~# s:envs_item) && (a:cur !~# s:envs_enditem))
|
let l:ind += &sw*((a:prev =~# s:envs_item) && (a:cur !~# s:envs_enditem))
|
||||||
@ -98,6 +101,7 @@ function! s:indent_envs(cur, prev) " {{{1
|
|||||||
return l:ind
|
return l:ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
let s:envs_ignored = '\v' . join(g:vimtex_indent_ignored_envs, '|')
|
||||||
let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography'
|
let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography'
|
||||||
let s:envs_item = '^\s*\\item'
|
let s:envs_item = '^\s*\\item'
|
||||||
let s:envs_beglist = '\\begin{\%(' . s:envs_lists . '\)'
|
let s:envs_beglist = '\\begin{\%(' . s:envs_lists . '\)'
|
||||||
|
@ -185,7 +185,7 @@ Expect tex (Verify):
|
|||||||
not affect verbatim environments!
|
not affect verbatim environments!
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
Given tex (Indent: Ampersands):
|
Given tex (Indent: ampersands):
|
||||||
\begin{tabular}{cc}
|
\begin{tabular}{cc}
|
||||||
\begin{tabular}{c}
|
\begin{tabular}{c}
|
||||||
Cell 1
|
Cell 1
|
||||||
@ -226,3 +226,33 @@ Expect tex (Verify):
|
|||||||
\end{aligned}
|
\end{aligned}
|
||||||
\end{equation}
|
\end{equation}
|
||||||
|
|
||||||
|
Given tex (Indent: ignored environments):
|
||||||
|
\documentclass{minimal}
|
||||||
|
\usepackage{amsmath}
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\begin{proof}
|
||||||
|
This statement is false.
|
||||||
|
\end{proof}
|
||||||
|
\end{document}
|
||||||
|
|
||||||
|
Execute (let g:vimtex_indent_ignored_envs = ...):
|
||||||
|
let g:vimtex_indent_ignored_envs = ['document', 'proof']
|
||||||
|
|
||||||
|
Do (Indent):
|
||||||
|
gg=G
|
||||||
|
|
||||||
|
Expect tex (Verify):
|
||||||
|
\documentclass{minimal}
|
||||||
|
\usepackage{amsmath}
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\begin{proof}
|
||||||
|
This statement is false.
|
||||||
|
\end{proof}
|
||||||
|
\end{document}
|
||||||
|
|
||||||
|
Given:
|
||||||
|
Execute (unlet g:vimtex_indent_ignored_envs):
|
||||||
|
unlet g:vimtex_indent_ignored_envs
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user