Add simple delimiter indent method
This commit is contained in:
parent
62340124d1
commit
185b129886
@ -158,6 +158,19 @@ 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 = {}
|
||||||
@ -216,7 +229,8 @@ 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
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ if !g:vimtex_indent_enabled | finish | endif
|
|||||||
call vimtex#util#set_default('g:vimtex_indent_ignored_envs', [
|
call vimtex#util#set_default('g:vimtex_indent_ignored_envs', [
|
||||||
\ 'document',
|
\ 'document',
|
||||||
\])
|
\])
|
||||||
|
call vimtex#util#set_default('g:vimtex_indent_delims_type', 'simple')
|
||||||
|
|
||||||
let s:cpo_save = &cpoptions
|
let s:cpo_save = &cpoptions
|
||||||
set cpoptions&vim
|
set cpoptions&vim
|
||||||
@ -56,7 +57,8 @@ function! VimtexIndent(lnum) " {{{1
|
|||||||
" Indent environments, delimiters, and tikz
|
" Indent environments, delimiters, and tikz
|
||||||
let l:ind = indent(l:prev_lnum)
|
let l:ind = indent(l:prev_lnum)
|
||||||
let l:ind += s:indent_envs(l:line, l:prev_line)
|
let l:ind += s:indent_envs(l:line, l:prev_line)
|
||||||
let l:ind += s:indent_delims(l:line, a:lnum, l:prev_line, l:prev_lnum)
|
let l:ind += s:indent_delims_{g:vimtex_indent_delims_type}(
|
||||||
|
\ l:line, a:lnum, l:prev_line, l:prev_lnum)
|
||||||
let l:ind += s:indent_tikz(l:prev_lnum, l:prev_line)
|
let l:ind += s:indent_tikz(l:prev_lnum, l:prev_line)
|
||||||
return l:ind
|
return l:ind
|
||||||
endfunction
|
endfunction
|
||||||
@ -110,7 +112,17 @@ let s:envs_begitem = s:envs_item . '\|' . s:envs_beglist
|
|||||||
let s:envs_enditem = s:envs_item . '\|' . s:envs_endlist
|
let s:envs_enditem = s:envs_item . '\|' . s:envs_endlist
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
function! s:indent_delims(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
|
||||||
|
|
||||||
|
return &sw*( max([ s:count(a:prev_line, s:re_delims[4])
|
||||||
|
\ - s:count(a:prev_line, s:re_delims[5]), 0])
|
||||||
|
\ - max([ s:count(a:line, s:re_delims[5])
|
||||||
|
\ - s:count(a:line, s:re_delims[4]), 0]))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" }}}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
|
||||||
|
|
||||||
let l:pre = s:split(a:prev_line, a:prev_lnum)
|
let l:pre = s:split(a:prev_line, a:prev_lnum)
|
||||||
@ -132,6 +144,8 @@ endfunction
|
|||||||
" s:re_delims[1] == math close
|
" s:re_delims[1] == math close
|
||||||
" s:re_delims[2] == text open
|
" s:re_delims[2] == text open
|
||||||
" s:re_delims[3] == text close
|
" s:re_delims[3] == text close
|
||||||
|
" s:re_delims[4] == math open only with modifier
|
||||||
|
" s:re_delims[5] == math close only with modifier
|
||||||
"
|
"
|
||||||
let s:re_delims = vimtex#delim#get_delim_regexes()
|
let s:re_delims = vimtex#delim#get_delim_regexes()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user