Improved the simple indent delim method

This commit is contained in:
Karl Yngve Lervåg 2017-02-05 11:06:58 +01:00
parent 185b129886
commit 1290aa5a56
2 changed files with 36 additions and 19 deletions

View File

@ -158,19 +158,6 @@ function! vimtex#delim#init_script() " {{{1
\ . '\)\|\\\%(left\|right\)\s*\.', \ . '\)\|\\\%(left\|right\)\s*\.',
\} \}
let s:re.delim_mathmod = {
\ 'open' : '\%(\%(' . s:re.delim_mods.open . '\)\s*\)\%('
\ . join(map(copy(s:delims.delim_math.re), 'v:val[0]'), '\|')
\ . '\)\|\\left\s*\.',
\ 'close' : '\%(\%(' . s:re.delim_mods.close . '\)\s*\)\%('
\ . join(map(copy(s:delims.delim_math.re), 'v:val[1]'), '\|')
\ . '\)\|\\right\s*\.',
\ 'both' : '\%(\%(' . s:re.delim_mods.both . '\)\s*\)\%('
\ . join(map(copy(s:delims.delim_math.re), 'v:val[0]'), '\|') . '\|'
\ . join(map(copy(s:delims.delim_math.re), 'v:val[1]'), '\|')
\ . '\)\|\\\%(left\|right\)\s*\.',
\}
let s:delims.env_all = {} let s:delims.env_all = {}
let s:delims.delim_all = {} let s:delims.delim_all = {}
let s:delims.all = {} let s:delims.all = {}
@ -229,8 +216,7 @@ endfunction
function! vimtex#delim#get_delim_regexes(...) " {{{1 function! vimtex#delim#get_delim_regexes(...) " {{{1
return exists('s:re') return exists('s:re')
\ ? [s:re.delim_math.open, s:re.delim_math.close, \ ? [s:re.delim_math.open, s:re.delim_math.close,
\ s:re.delim_tex.open, s:re.delim_tex.close, \ s:re.delim_tex.open, s:re.delim_tex.close]
\ s:re.delim_mathmod.open, s:re.delim_mathmod.close]
\ : [] \ : []
endfunction endfunction

View File

@ -115,12 +115,43 @@ let s:envs_enditem = s:envs_item . '\|' . s:envs_endlist
function! s:indent_delims_simple(line, lnum, prev_line, prev_lnum) " {{{1 function! s:indent_delims_simple(line, lnum, prev_line, prev_lnum) " {{{1
if empty(s:re_delims) | return 0 | endif if empty(s:re_delims) | return 0 | endif
return &sw*( max([ s:count(a:prev_line, s:re_delims[4]) return &sw*( max([ s:count(a:prev_line, s:re_open)
\ - s:count(a:prev_line, s:re_delims[5]), 0]) \ - s:count(a:prev_line, s:re_close), 0])
\ - max([ s:count(a:line, s:re_delims[5]) \ - max([ s:count(a:line, s:re_close)
\ - s:count(a:line, s:re_delims[4]), 0])) \ - s:count(a:line, s:re_open), 0]))
endfunction endfunction
let s:delims_open = [
\ '\(',
\ '\[',
\ '\\\{',
\ '\\langle',
\ '\\lvert',
\ '\\lfloor',
\ '\\lceil',
\ '\\ulcorner',
\]
let s:delims_close = [
\ '\)',
\ '\]',
\ '\\\}',
\ '\\rangle',
\ '\\rvert',
\ '\\rfloor',
\ '\\rceil',
\ '\\urcorner',
\]
let s:re_open = '\v'
\ . '%(\\left|\\[bB]igg?l?)\s*%(' . join(s:delims_open, '|') . ')'
\ . '|\\left\s*\.'
\ . '|\{'
\ . '|\\\['
let s:re_close = '\v'
\ . '%(\\right|\\[bB]igg?r?)\s*%(' . join(s:delims_close, '|') . ')'
\ . '|\\right\s*\.'
\ . '|\}'
\ . '|\\\]'
" }}}1 " }}}1
function! s:indent_delims_complex(line, lnum, prev_line, prev_lnum) " {{{1 function! s:indent_delims_complex(line, lnum, prev_line, prev_lnum) " {{{1
if empty(s:re_delims) | return 0 | endif if empty(s:re_delims) | return 0 | endif