Add option for stopline tolerance (#386)

This commit is contained in:
Karl Yngve Lervåg 2016-03-05 22:43:53 +01:00
parent e3972d8aad
commit 2fd3a4ba96
2 changed files with 22 additions and 10 deletions

View File

@ -7,10 +7,13 @@
function! vimtex#delim#init_options() " {{{1
call vimtex#util#set_default('g:vimtex_delim_toggle_mod_list',
\ [['\left', '\right']])
call vimtex#util#set_default('g:vimtex_delim_stopline', 500)
endfunction
" }}}1
function! vimtex#delim#init_script() " {{{1
let s:stopline = g:vimtex_delim_stopline
let s:delims = {}
let s:re = {}
@ -407,9 +410,9 @@ function! s:get_delim(direction, type, side) " {{{1
"
let l:re = s:re[a:type][a:side]
let [l:lnum, l:cnum] = a:direction ==# 'next'
\ ? searchpos(l:re, 'cnW', line('w$') + 200)
\ ? searchpos(l:re, 'cnW', line('w$') + s:stopline)
\ : a:direction ==# 'prev'
\ ? searchpos(l:re, 'bcnW', max([line('w0') - 200, 1]))
\ ? searchpos(l:re, 'bcnW', max([line('w0') - s:stopline, 1]))
\ : searchpos(l:re, 'bcnW', line('.'))
let l:match = matchstr(getline(l:lnum), '^' . l:re, l:cnum-1)
@ -625,8 +628,8 @@ endfunction
function! s:get_matching_env() dict " {{{1
let [re, flags, stopline] = self.is_open
\ ? [self.re.close, 'nW', line('w$') + 200]
\ : [self.re.open, 'bnW', max([line('w0') - 200, 1])]
\ ? [self.re.close, 'nW', line('w$') + s:stopline]
\ : [self.re.open, 'bnW', max([line('w0') - s:stopline, 1])]
let [lnum, cnum] = searchpairpos(self.re.open, '', self.re.close,
\ flags, '', stopline)
@ -638,8 +641,8 @@ endfunction
" }}}1
function! s:get_matching_tex() dict " {{{1
let [re, flags, stopline] = self.is_open
\ ? [self.re.open, 'nW', line('w$') + 200]
\ : [self.re.open, 'bnW', max([line('w0') - 200, 1])]
\ ? [self.re.open, 'nW', line('w$') + s:stopline]
\ : [self.re.open, 'bnW', max([line('w0') - s:stopline, 1])]
let [lnum, cnum] = searchpos(re, flags, stopline)
let match = matchstr(getline(lnum), '^' . re, cnum-1)
@ -650,8 +653,8 @@ endfunction
" }}}1
function! s:get_matching_latex() dict " {{{1
let [re, flags, stopline] = self.is_open
\ ? [self.re.close, 'nW', line('w$') + 200]
\ : [self.re.open, 'bnW', max([line('w0') - 200, 1])]
\ ? [self.re.close, 'nW', line('w$') + s:stopline]
\ : [self.re.open, 'bnW', max([line('w0') - s:stopline, 1])]
let [lnum, cnum] = searchpos(re, flags, stopline)
let match = matchstr(getline(lnum), '^' . re, cnum-1)
@ -662,8 +665,8 @@ endfunction
" }}}1
function! s:get_matching_delim() dict " {{{1
let [re, flags, stopline] = self.is_open
\ ? [self.re.close, 'nW', line('w$') + 200]
\ : [self.re.open, 'bnW', max([line('w0') - 200, 1])]
\ ? [self.re.close, 'nW', line('w$') + s:stopline]
\ : [self.re.open, 'bnW', max([line('w0') - s:stopline, 1])]
let [lnum, cnum] = searchpairpos(self.re.open, '', self.re.close,
\ flags, '', stopline)

View File

@ -403,6 +403,15 @@ Options~
<
Default value: [['\left', '\right']]
*g:vimtex_delim_stopline*
A tolerance for the number of lines to search for matching delimiters in
each direction. It is used in an expression for the {stopline} argument of
|search()| function calls. If the option is increased it will make the
matching more accurate, at the expense of potential lags. The default value
should work well for most people.
Default value: 500
*g:vimtex_format_enabled*
If enabled, |vimtex| uses a custom |formatexpr| that should handle inline
comments. That is, if it is enabled, then comments at end of lines will not