Skip to content

Commit

Permalink
Use empty dict to disable indented conditionals (cf. #1078)
Browse files Browse the repository at this point in the history
  • Loading branch information
lervag committed Mar 20, 2018
1 parent 68ee878 commit a4211c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 0 additions & 3 deletions autoload/vimtex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ function! vimtex#init_options() " {{{1
\ { 'lhs' : 'vr', 'rhs' : '\varrho' },
\])

" Note: Default values are given in 'indent/tex.vim'
call s:init_option('vimtex_indent_conditionals', {})

call s:init_option('vimtex_index_hide_line_numbers', 1)
call s:init_option('vimtex_index_resize', 0)
call s:init_option('vimtex_index_show_help', 1)
Expand Down
5 changes: 2 additions & 3 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1233,15 +1233,14 @@ Options~
Default value: 1

*g:vimtex_indent_conditionals*
This is a dictionary that defines regexes for indenting conditionals. To
disable this type of indentation, set the `disabled` key to 1.
This is a dictionary that defines regexes for indenting conditionals. Set it
to an empty dictionary to disable this type of indentation.

Default value: >
let g:vimtex_indent_conditionals = {
\ 'open': '\v%(\\newif)@<!\\if%(field|name|numequal|thenelse)@!',
\ 'else': '\\else\>',
\ 'close': '\\fi\>',
\ 'disabled': 0,
\}
*g:vimtex_indent_delims*
Expand Down
17 changes: 13 additions & 4 deletions indent/tex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,26 @@ endif

" }}}1
function! s:indent_conditionals(line, lnum, prev_line, prev_lnum) abort " {{{1
if get(g:vimtex_indent_conditionals, 'disabled') | return 0 | endif

" Create script local regex dict based on user options
if !exists('s:re_cond')
let l:cfg = {}

if exists('g:vimtex_indent_conditionals')
let l:cfg = g:vimtex_indent_conditionals
if empty(l:cfg)
let s:re_cond = {}
return 0
endif
endif

let s:re_cond = extend({
\ 'open': '\v(\\newif)@<!\\if(field|name|numequal|thenelse)@!',
\ 'else': '\\else\>',
\ 'close': '\\fi\>',
\}, g:vimtex_indent_conditionals)
\}, l:cfg)
endif

if empty(s:re_cond) | return 0 | endif

" Match for conditional indents
if a:line =~# s:re_cond.close
silent! unlet s:conditional_opened
Expand Down

0 comments on commit a4211c8

Please sign in to comment.