Inside prev Z% motion again

This commit is contained in:
Andy K. Massimino
2021-10-16 14:36:51 -04:00
parent 0981e4d5e0
commit 97ffd1a206
2 changed files with 63 additions and 0 deletions

View File

@@ -294,6 +294,16 @@ function! s:motion_init_module() " {{{1
onoremap <silent> <plug>(matchup-z%)
\ :<c-u>call matchup#motion#op('z%')<cr>
" 'opposite' of z%
nnoremap <silent> <plug>(matchup-Z%)
\ :<c-u>call matchup#motion#jump_inside_prev(0)<cr>
xnoremap <silent> <sid>(matchup-Z%)
\ :<c-u>call matchup#motion#jump_inside_prev(1)<cr>
xmap <silent> <plug>(matchup-Z%) <sid>(matchup-Z%)
onoremap <silent> <plug>(matchup-Z%)
\ :<c-u>call matchup#motion#op('Z%')<cr>
inoremap <silent> <plug>(matchup-c_g%)
\ <c-\><c-o>:call matchup#motion#insert_mode()<cr>

View File

@@ -312,6 +312,59 @@ function! matchup#motion#jump_inside(visual) " {{{1
call matchup#pos#set_cursor(l:new_pos)
endfunction
" }}}1
function! matchup#motion#jump_inside_prev(visual) abort " {{{1
let l:count = v:count1
let l:save_pos = matchup#pos#get_cursor()
call matchup#perf#timeout_start(750)
if a:visual
normal! gv
endif
for l:counter in range(l:count + 1)
if l:counter
let l:delim = matchup#delim#get_prev('all', 'open')
else
let l:delim = matchup#delim#get_current('all', 'open')
if empty(l:delim)
let l:delim = matchup#delim#get_prev('all', 'open')
endif
endif
if empty(l:delim)
call matchup#pos#set_cursor(l:save_pos)
return
endif
let l:new_pos = [l:delim.lnum, l:delim.cnum]
call matchup#pos#set_cursor(matchup#pos#prev(l:delim))
let l:new_pos[1] += matchup#delim#end_offset(l:delim)
endfor
call matchup#pos#set_cursor(l:save_pos)
" convert to [~, lnum, cnum, ~] format
let l:new_pos = matchup#pos#next(l:new_pos)
let l:is_oper = !empty(get(s:, 'v_operator', ''))
" handle selection option 'exclusive'
if l:is_oper && &selection ==# 'exclusive'
let l:new_pos = matchup#pos#next_eol(l:new_pos)
" normal! o
" call matchup#pos#set_cursor(matchup#pos#next_eol(
" \ matchup#pos#get_cursor()))
" normal! o
endif
if !g:matchup_motion_keepjumps
normal! m`
endif
call matchup#pos#set_cursor(l:new_pos)
endfunction
" }}}1
function! matchup#motion#insert_mode() " {{{1
call matchup#perf#timeout_start(0) " disable the timeout