From 7d740682d68e347edc17d30e1479653fefb10d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Mon, 5 Dec 2016 22:23:51 +0100 Subject: [PATCH] Fix #634: Add option to ignore indents on envs --- doc/vimtex.txt | 5 +++++ indent/tex.vim | 8 ++++++-- test/vader/indentation.vader | 32 +++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 5a70431..2dece67 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -590,6 +590,11 @@ Options~ Default value: 1 +*g:vimtex_indent_ignored_envs* + List of environments that should not add/reduce indentation. + + Default value: ['document'] + *g:vimtex_index_resize* Whether or not to automatically resize vim when index windows are opened. diff --git a/indent/tex.vim b/indent/tex.vim index 296b758..561e3d6 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -12,6 +12,9 @@ let b:did_vimtex_indent = 1 call vimtex#util#set_default('g:vimtex_indent_enabled', 1) if !g:vimtex_indent_enabled | finish | endif +call vimtex#util#set_default('g:vimtex_indent_ignored_envs', [ + \ 'document', + \]) let s:cpo_save = &cpo set cpo&vim @@ -87,8 +90,8 @@ function! s:indent_envs(cur, prev) " {{{1 let l:ind = 0 " First for general environments - let l:ind += &sw*((a:prev =~# '\\begin{.*}') && (a:prev !~# 'document')) - let l:ind -= &sw*((a:cur =~# '\\end{.*}') && (a:cur !~# 'document')) + let l:ind += &sw*((a:prev =~# '\\begin{.*}') && (a:prev !~# s:envs_ignored)) + let l:ind -= &sw*((a:cur =~# '\\end{.*}') && (a:cur !~# s:envs_ignored)) " Indentation for prolonged items in lists 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 endfunction +let s:envs_ignored = '\v' . join(g:vimtex_indent_ignored_envs, '|') let s:envs_lists = 'itemize\|description\|enumerate\|thebibliography' let s:envs_item = '^\s*\\item' let s:envs_beglist = '\\begin{\%(' . s:envs_lists . '\)' diff --git a/test/vader/indentation.vader b/test/vader/indentation.vader index 89444e4..c93f16b 100644 --- a/test/vader/indentation.vader +++ b/test/vader/indentation.vader @@ -185,7 +185,7 @@ Expect tex (Verify): not affect verbatim environments! \end{lstlisting} -Given tex (Indent: Ampersands): +Given tex (Indent: ampersands): \begin{tabular}{cc} \begin{tabular}{c} Cell 1 @@ -226,3 +226,33 @@ Expect tex (Verify): \end{aligned} \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 +