mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-18 01:38:57 +00:00
Make some minor cleanups
This commit is contained in:
@@ -34,7 +34,7 @@ function! matchup#delim#get_current(type, side, ...) abort " {{{1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#delim#get_surrounding(type, count, opts) " {{{1
|
||||
function! matchup#delim#get_surrounding(type, count, opts) abort " {{{1
|
||||
return matchup#delim#get_surrounding_impl(a:type, a:count, a:opts)
|
||||
endfunction
|
||||
|
||||
@@ -118,7 +118,7 @@ function! matchup#delim#get_matching(delim, ...) abort " {{{1
|
||||
let l:matching.match = l:match
|
||||
let l:matching.side = l:i == 0 ? 'open'
|
||||
\ : l:i == len(l:matches)-1 ? 'close' : 'mid'
|
||||
let l:matching.class[1] = 'FIXME'
|
||||
let l:matching.class[1] = '__mid__'
|
||||
let l:matching.match_index = l:i
|
||||
|
||||
call add(l:matching_list, l:matching)
|
||||
@@ -149,7 +149,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
function! matchup#delim#get_surrounding_impl(type, ...) " {{{1
|
||||
function! matchup#delim#get_surrounding_impl(type, ...) abort " {{{1
|
||||
call matchup#perf#tic('delim#get_surrounding')
|
||||
|
||||
let l:save_pos = matchup#pos#get_cursor()
|
||||
@@ -257,7 +257,7 @@ let s:cache = {}
|
||||
let s:cache_valid = {}
|
||||
|
||||
" }}}1
|
||||
function! matchup#delim#get_surround_nearest(open, ...) " {{{1
|
||||
function! matchup#delim#get_surround_nearest(open, ...) abort " {{{1
|
||||
" finds the first consecutive pair whose start
|
||||
" positions surround pos (default to the cursor)
|
||||
let l:cur_pos = a:0 ? a:1 : matchup#pos#get_cursor()
|
||||
@@ -283,7 +283,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
function! matchup#delim#jump_target(delim) " {{{1
|
||||
function! matchup#delim#jump_target(delim) abort " {{{1
|
||||
let l:save_pos = matchup#pos#get_cursor()
|
||||
|
||||
" unicode note: technically wrong, but works in practice
|
||||
@@ -311,7 +311,7 @@ function! matchup#delim#jump_target(delim) " {{{1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#delim#end_offset(delim) " {{{1
|
||||
function! matchup#delim#end_offset(delim) abort " {{{1
|
||||
return max([0, match(a:delim.match, '.$')])
|
||||
endfunction
|
||||
|
||||
@@ -332,21 +332,27 @@ function! s:get_delim(opts) abort " {{{1
|
||||
" 'side' : 'open' | 'close'
|
||||
" | 'both' | 'mid'
|
||||
" | 'both_all' | 'open_mid'
|
||||
" }
|
||||
" }
|
||||
"
|
||||
" }}}2
|
||||
" returns: {{{2
|
||||
" delim = { (TODO update)
|
||||
" type : 'delim'
|
||||
" delim = {
|
||||
" lnum : line number
|
||||
" cnum : column number
|
||||
" type : e.g., 'delim_tex'
|
||||
" match : the actual text match
|
||||
" augment : how to match a corresponding open
|
||||
" groups : dict of captured groups
|
||||
" side : 'open' | 'close' | 'mid'
|
||||
" class : [ c1, c2 ] identifies the kind of match_words
|
||||
" regexone : the regex item, like \1foo
|
||||
" regextwo : the regex_capture item, like \(group\)foo
|
||||
" skip : skip state
|
||||
" get_matching: callback used to get matching delims
|
||||
" highlighting: whether the request was for highlighting
|
||||
"
|
||||
" ... Parser dependent ...
|
||||
" augment : how to match a corresponding open
|
||||
" groups : dict of captured groups
|
||||
" regexone : the regex items, like \1foo
|
||||
" regextwo : the regex_capture items, like \(group\)foo
|
||||
" midmap : ??
|
||||
" }
|
||||
"
|
||||
" }}}2
|
||||
@@ -375,7 +381,7 @@ function! s:get_delim(opts) abort " {{{1
|
||||
let l:cursorpos -= 1
|
||||
endif
|
||||
|
||||
let s:invert_skip = 0
|
||||
call matchup#delim#set_invert_skip(0)
|
||||
|
||||
if a:opts.direction ==# 'current'
|
||||
let l:check_skip = get(a:opts, 'check_skip',
|
||||
@@ -501,12 +507,8 @@ function! s:get_delim(opts) abort " {{{1
|
||||
\ 'cnum' : l:cnum,
|
||||
\ 'type' : '',
|
||||
\ 'match' : '',
|
||||
\ 'augment' : '',
|
||||
\ 'groups' : '',
|
||||
\ 'side' : '',
|
||||
\ 'class' : [],
|
||||
\ 'regexone' : '',
|
||||
\ 'regextwo' : '',
|
||||
\ 'skip' : l:skip_state,
|
||||
\}
|
||||
|
||||
@@ -622,7 +624,7 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
|
||||
let l:match = l:matches[0]
|
||||
|
||||
let l:list = b:matchup_delim_lists[a:opts.type]
|
||||
let l:thisrenr = l:list.regex[l:i / l:ns]
|
||||
let l:thisregex = l:list.regex[l:i / l:ns]
|
||||
let l:thisrecap = l:list.regex_capture[l:i / l:ns]
|
||||
|
||||
let l:augment = {}
|
||||
@@ -668,7 +670,7 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
|
||||
\ 'side' : l:side,
|
||||
\ 'class' : [(l:i / l:ns), l:id],
|
||||
\ 'get_matching' : s:engines.classic.get_matching,
|
||||
\ 'regexone' : l:thisrenr,
|
||||
\ 'regexone' : l:thisregex,
|
||||
\ 'regextwo' : l:thisrecap,
|
||||
\ 'midmap' : get(l:list, 'midmap', {}),
|
||||
\ 'highlighting' : get(a:opts, 'highlighting', 0),
|
||||
@@ -695,7 +697,7 @@ function! s:get_matching_delims(down, stopline) dict abort " {{{1
|
||||
let l:open = self.regexone.open " TODO is this right? BADLOGIC
|
||||
let l:close = self.regexone.close
|
||||
|
||||
" if we're searching up, we anchor by the augment, if it exists
|
||||
" if we're searching up, we anchor by the augment string, if it exists
|
||||
if !a:down && !empty(self.augment)
|
||||
let l:open = self.augment.str
|
||||
endif
|
||||
@@ -715,7 +717,7 @@ function! s:get_matching_delims(down, stopline) dict abort " {{{1
|
||||
let l:open = matchup#delim#fill_backrefs(l:open, self.groups, 0)
|
||||
let l:close = matchup#delim#fill_backrefs(l:close, self.groups, 0)
|
||||
|
||||
let s:invert_skip = self.skip
|
||||
call matchup#delim#set_invert_skip(self.skip)
|
||||
if empty(b:matchup_delim_skip)
|
||||
let l:skip = 'matchup#delim#skip_default()'
|
||||
else
|
||||
@@ -880,6 +882,8 @@ function! matchup#delim#skip_default()
|
||||
\ ? !s:invert_skip : s:invert_skip
|
||||
endfunction
|
||||
|
||||
""
|
||||
" regular skip expression at cursor
|
||||
function! matchup#delim#skip0()
|
||||
let s:eff_curpos = [line('.'), col('.')]
|
||||
execute 'return' (s:invert_skip ? '!(' : '(') b:matchup_delim_skip ')'
|
||||
@@ -906,6 +910,11 @@ function! matchup#delim#skip2(strike, def)
|
||||
endfunction
|
||||
|
||||
let s:invert_skip = 0
|
||||
|
||||
function! matchup#delim#set_invert_skip(val) abort
|
||||
let s:invert_skip = a:val
|
||||
endfunction
|
||||
|
||||
let s:eff_curpos = [1, 1]
|
||||
|
||||
" effective column/line
|
||||
@@ -923,7 +932,7 @@ endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
function! matchup#delim#fill_backrefs(re, groups, warn) " {{{1
|
||||
function! matchup#delim#fill_backrefs(re, groups, warn) abort " {{{1
|
||||
return substitute(a:re, g:matchup#re#backref,
|
||||
\ '\=s:get_backref(a:groups, submatch(1), a:warn)', 'g')
|
||||
" \ '\=get(a:groups, submatch(1), "")', 'g')
|
||||
@@ -988,4 +997,3 @@ let s:engines = {
|
||||
let &cpo = s:save_cpo
|
||||
|
||||
" vim: fdm=marker sw=2
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ function! matchup#loader#refresh_match_words() abort " {{{1
|
||||
" protect the cursor from the match_words function
|
||||
let l:save_pos = matchup#pos#get_cursor()
|
||||
let l:match_words = ''
|
||||
execute 'let l:match_words = ' b:match_words
|
||||
execute 'let l:match_words =' b:match_words
|
||||
if l:save_pos != matchup#pos#get_cursor()
|
||||
call matchup#pos#set_cursor(l:save_pos)
|
||||
endif
|
||||
@@ -169,7 +169,7 @@ function! s:init_delim_lists(no_words, filter_words) abort " {{{1
|
||||
let l:sets = split(l:match_words, g:matchup#re#not_bslash.',')
|
||||
|
||||
if a:filter_words
|
||||
call filter(l:sets, 'v:val =~ "^[^a-zA-Z]\\{3,18\\}$"')
|
||||
call filter(l:sets, 'v:val =~? "^[^a-zA-Z]\\{3,18\\}$"')
|
||||
if empty(l:sets)
|
||||
return s:init_delim_lists_fast(l:match_words)
|
||||
endif
|
||||
@@ -250,7 +250,7 @@ function! s:init_delim_lists(no_words, filter_words) abort " {{{1
|
||||
endfor
|
||||
|
||||
" for the 'open' pattern, create a series of replacements
|
||||
" of the capture groups with \9, \8, ..., \1
|
||||
" of the capture groups with corresponding \9, \8, ..., \1
|
||||
" this must be done deepest to shallowest
|
||||
let l:augments = {}
|
||||
let l:order = matchup#loader#capture_group_replacement_order(l:cg)
|
||||
|
||||
Reference in New Issue
Block a user