Skip to content

Commit

Permalink
Fix matchup-Z% motion, fix #368
Browse files Browse the repository at this point in the history
  • Loading branch information
andymass committed Oct 28, 2024
1 parent fea05cf commit 9b21868
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
46 changes: 26 additions & 20 deletions autoload/matchup/motion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -324,39 +324,45 @@ function! matchup#motion#jump_inside_prev(visual) abort " {{{1
normal! gv
endif

for l:counter in range(l:count + 1)
if l:counter
for l:counter in range(l:count)
let l:delim = matchup#delim#get_current('all', 'open')
if !empty(l:delim)
call matchup#pos#set_cursor(matchup#pos#prev(l:delim))
endif

for l:tries in range(2)
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')
call matchup#pos#set_cursor(l:save_pos)
return
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)
let l:new_pos = matchup#pos#(l:delim)
let l:new_pos[1] += matchup#delim#end_offset(l:delim)
let l:new_pos = matchup#pos#next(l:new_pos)

" jump ahead if inside indent
if matchup#util#in_indent(l:new_pos[1], l:new_pos[2])
let l:new_pos[2] = 1 + strlen(matchstr(
\ getline(l:new_pos[1]), '^\s\+'))
endif

if matchup#pos#smaller(l:new_pos, l:save_pos)
break
endif

call matchup#pos#set_cursor(matchup#pos#prev_eol(l:delim))
endfor
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
Expand Down
1 change: 1 addition & 0 deletions doc/matchup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ the corresponding default left-hand side will not be mapped.
[% |<plug>(matchup-[%)| nx motion
]% |<plug>(matchup-]%)| nx motion
z% |<plug>(matchup-z%)| nx motion
(none) |<plug>(matchup-Z%)| nx motion
a% |<plug>(matchup-a%)| x text_obj
i% |<plug>(matchup-i%)| x text_obj
ds% |<plug>(matchup-ds%)| n surround
Expand Down

0 comments on commit 9b21868

Please sign in to comment.