Improve handling of ignorecase re #33

This commit is contained in:
Andy K. Massimino
2018-06-18 09:17:55 -04:00
parent 93659b0ff0
commit f5af60fd5e
2 changed files with 22 additions and 51 deletions

View File

@@ -333,8 +333,7 @@ function! s:get_delim(opts) " {{{1
let l:re .= '\&'
endif
" use b:match_ignorecase
call s:ignorecase_start()
" use b:match_ignorecase (defunct)
" move cursor one left for searchpos if necessary
let l:need_restore_cursor = 0
@@ -391,8 +390,7 @@ function! s:get_delim(opts) " {{{1
let l:need_restore_cursor = 1
endif
" reset ignorecase
call s:ignorecase_end()
" reset ignorecase (defunct)
" restore cursor
if l:need_restore_cursor
@@ -445,36 +443,6 @@ endfunction
" }}}1
function! s:ignorecase_start() " {{{1
" enforce b:match_ignorecase, if necessary
if exists('s:save_ic') || exists('s:save_scs')
return
endif
if exists('b:match_ignorecase') && b:match_ignorecase !=# &ignorecase
let s:save_ic = &ignorecase
noautocmd let &ignorecase = b:match_ignorecase
endif
if &smartcase
let s:save_scs = &smartcase
noautocmd let &smartcase = 0
endif
endfunction
"}}}1
function! s:ignorecase_end() " {{{1
" restore ignorecase
if exists('s:save_ic')
noautocmd let &ignorecase = s:save_ic
unlet s:save_ic
endif
if exists('s:save_scs')
noautocmd let &smartcase = s:save_scs
unlet s:save_scs
endif
endfunction
"}}}1
function! s:parser_delim_new(lnum, cnum, opts) " {{{1
let l:cursorpos = a:opts.cursorpos
let l:found = 0
@@ -483,7 +451,7 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
let l:rebrs = b:matchup_delim_lists[a:opts.type].regex_backref
" use b:match_ignorecase
call s:ignorecase_start()
let l:ic = get(b:, 'match_ignorecase', 0) ? '\c' : '\C'
" loop through all (index, side) pairs,
let l:ns = len(l:sides)
@@ -510,7 +478,7 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
" prepend the column number and append the cursor column
" to anchor the match; we don't use {start} for matchlist
" because there may be zero-width look behinds
let l:re_anchored = s:anchor_regex(l:re, a:cnum, l:has_zs)
let l:re_anchored = l:ic . s:anchor_regex(l:re, a:cnum, l:has_zs)
" for current we want the first match which the cursor is inside
if a:opts.direction ==# 'current'
@@ -541,8 +509,7 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
break
endfor
" reset ignorecase
call s:ignorecase_end()
" reset ignorecase (defunct)
if !l:found
return {}
@@ -655,7 +622,9 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
endif
" use b:match_ignorecase
call s:ignorecase_start()
let l:ic = get(b:, 'match_ignorecase', 0) ? '\c' : '\C'
let l:open = l:ic . l:open
let l:close = l:ic . l:close
let [l:lnum_corr, l:cnum_corr] = searchpairpos(l:open, '', l:close,
\ 'n'.l:flags, l:skip, l:stopline, matchup#perf#timeout())
@@ -664,20 +633,18 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
" if nothing found, bail immediately
if l:lnum_corr == 0
" reset ignorecase
call s:ignorecase_end()
" reset ignorecase (defunct)
return [['', 0, 0]]
endif
" get the match and groups
let l:has_zs = self.regextwo.extra_info.has_zs
let l:re_anchored = s:anchor_regex(l:re, l:cnum_corr, l:has_zs)
let l:re_anchored = l:ic . s:anchor_regex(l:re, l:cnum_corr, l:has_zs)
let l:matches = matchlist(getline(l:lnum_corr), l:re_anchored)
let l:match_corr = l:matches[0]
" reset ignorecase
call s:ignorecase_end()
" reset ignorecase (defunct)
" store these in these groups
if a:down
@@ -707,7 +674,8 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
let l:re = l:mids
" use b:match_ignorecase
call s:ignorecase_start()
let l:mid = l:ic . l:mids
let l:re = l:ic . l:re
let l:list = []
while 1
@@ -732,8 +700,7 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
call add(l:list, [l:match, l:lnum, l:cnum])
endwhile
" reset ignorecase
call s:ignorecase_end()
" reset ignorecase (defunct)
call add(l:list, [l:match_corr, l:lnum_corr, l:cnum_corr])

View File

@@ -453,15 +453,19 @@ function! s:init_delim_regexes() abort " {{{1
let l:re.delim_tex = s:init_delim_regexes_generator('delim_tex')
let l:re.delim_tex._engine_info = { 'has_zs': {} }
" use a flag for b:match_ignorecase
let l:ic = get(b:, 'match_ignorecase', 0) ? '\c' : '\C'
for l:k in keys(s:sidedict)
let l:re.delim_tex._engine_info.has_zs[l:k]
\ = l:re.delim_tex[l:k] =~# g:matchup#re#zs
" be explicit about regex mode (set magic mode)
let l:re.delim_tex[l:k] = '\m' . l:re.delim_tex[l:k]
if l:re.delim_tex[l:k] ==# '\m\%(\)'
if l:re.delim_tex[l:k] ==# '\%(\)'
let l:re.delim_tex[l:k] = ''
else
" since these patterns are used in searchpos(),
" be explicit about regex mode (set magic mode and ignorecase)
let l:re.delim_tex[l:k] = '\m' . l:ic . l:re.delim_tex[l:k]
endif
let l:re.delim_all[l:k] = l:re.delim_tex[l:k]