From 185b129886136100e2bdbc538c74bdcf5eeeac49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Wed, 1 Feb 2017 13:07:57 +0100 Subject: [PATCH] Add simple delimiter indent method --- autoload/vimtex/delim.vim | 16 +++++++++++++++- indent/tex.vim | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/autoload/vimtex/delim.vim b/autoload/vimtex/delim.vim index e041ada..159cd1b 100644 --- a/autoload/vimtex/delim.vim +++ b/autoload/vimtex/delim.vim @@ -158,6 +158,19 @@ function! vimtex#delim#init_script() " {{{1 \ . '\)\|\\\%(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.delim_all = {} let s:delims.all = {} @@ -216,7 +229,8 @@ endfunction function! vimtex#delim#get_delim_regexes(...) " {{{1 return exists('s:re') \ ? [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 diff --git a/indent/tex.vim b/indent/tex.vim index b55675a..a2db851 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -15,6 +15,7 @@ if !g:vimtex_indent_enabled | finish | endif call vimtex#util#set_default('g:vimtex_indent_ignored_envs', [ \ 'document', \]) +call vimtex#util#set_default('g:vimtex_indent_delims_type', 'simple') let s:cpo_save = &cpoptions set cpoptions&vim @@ -56,7 +57,8 @@ function! VimtexIndent(lnum) " {{{1 " Indent environments, delimiters, and tikz let l:ind = indent(l:prev_lnum) 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) return l:ind 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 " }}}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 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[2] == text open " 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()