mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-17 17:38:01 +00:00
Allow motions and objects to fail with best found
re. #16 Adds option g:matchup_delim_count_fail
This commit is contained in:
@@ -25,9 +25,11 @@ function! s:init_options()
|
||||
|
||||
call s:init_option('matchup_matchparen_timeout',
|
||||
\ get(g:, 'matchparen_timeout', 300))
|
||||
call s:init_option('matchup_matchparen_insert_timeout',
|
||||
call s:init_option('matchup_matchparen_insert_timeout',
|
||||
\ get(g:, 'matchparen_insert_timeout', 60))
|
||||
|
||||
call s:init_option('matchup_delim_count_fail', 0)
|
||||
|
||||
call s:init_option('matchup_motion_enabled', 1)
|
||||
call s:init_option('matchup_motion_cursor_end', 1)
|
||||
call s:init_option('matchup_motion_override_Npercent', 6)
|
||||
@@ -38,7 +40,7 @@ function! s:init_options()
|
||||
call s:init_option('matchup_transmute_enabled', 0)
|
||||
|
||||
call s:init_option('matchup_imap_enabled', 0)
|
||||
|
||||
|
||||
call s:init_option('matchup_complete_enabled', 0)
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -209,15 +209,19 @@ function! matchup#delim#get_surrounding(type, ...) " {{{1
|
||||
" provided count == 0 refers to local any block
|
||||
let l:local = l:count == 0 ? 1 : 0
|
||||
|
||||
let l:opts = {}
|
||||
let s:invert_skip = 0
|
||||
if matchup#delim#skip() " TODO: check for insert mode
|
||||
let l:opts.check_skip = 0
|
||||
let l:delimopts = {}
|
||||
let s:invert_skip = 0 " TODO: this logic is still bad
|
||||
if matchup#delim#skip() " TODO: check for insert mode (?)
|
||||
let l:delimopts.check_skip = 0
|
||||
endif
|
||||
|
||||
" keep track of the outermost pair found so far
|
||||
" returned when g:matchup_delim_count_fail = 1
|
||||
let l:best = []
|
||||
|
||||
while l:pos_val_open < l:pos_val_last
|
||||
let l:open = matchup#delim#get_prev(a:type,
|
||||
\ l:local ? 'open_mid' : 'open', l:opts)
|
||||
\ l:local ? 'open_mid' : 'open', l:delimopts)
|
||||
if empty(l:open) | break | endif
|
||||
|
||||
let l:matches = matchup#delim#get_matching(l:open, 1)
|
||||
@@ -237,6 +241,7 @@ function! matchup#delim#get_surrounding(type, ...) " {{{1
|
||||
endif
|
||||
call matchup#pos#set_cursor(matchup#pos#prev(l:open))
|
||||
let l:counter -= 1
|
||||
let l:best = [l:open, l:close]
|
||||
else
|
||||
call matchup#pos#set_cursor(matchup#pos#prev(l:open))
|
||||
let l:pos_val_last = l:pos_val_open
|
||||
@@ -244,6 +249,12 @@ function! matchup#delim#get_surrounding(type, ...) " {{{1
|
||||
endif
|
||||
endwhile
|
||||
|
||||
if !empty(l:best) && g:matchup_delim_count_fail
|
||||
call matchup#pos#set_cursor(l:save_pos)
|
||||
call matchup#perf#toc('delim#get_surrounding', 'bad_count')
|
||||
return l:best
|
||||
endif
|
||||
|
||||
" restore cursor and return failure
|
||||
call matchup#pos#set_cursor(l:save_pos)
|
||||
call matchup#perf#toc('delim#get_surrounding', 'fail')
|
||||
|
||||
@@ -203,8 +203,8 @@ function! matchup#motion#find_unmatched(visual, down) " {{{1
|
||||
normal! gv
|
||||
endif
|
||||
|
||||
" disable the timeout
|
||||
call matchup#perf#timeout_start(0)
|
||||
" set the timeout fairly high
|
||||
call matchup#perf#timeout_start(750)
|
||||
|
||||
for l:second_try in range(2)
|
||||
let [l:open, l:close] = matchup#delim#get_surrounding('delim_all',
|
||||
|
||||
@@ -57,8 +57,8 @@ function! matchup#text_obj#delimited(is_inner, visual, type) " {{{1
|
||||
let l:linewise_op = 1
|
||||
endif
|
||||
|
||||
" disable the timeout
|
||||
call matchup#perf#timeout_start(0)
|
||||
" set the timeout fairly high
|
||||
call matchup#perf#timeout_start(725)
|
||||
|
||||
" try up to four times
|
||||
for l:try_again in range(4)
|
||||
|
||||
@@ -525,12 +525,15 @@ Module motion~
|
||||
|
||||
Default: 1
|
||||
|
||||
*g:matchup_motion_count_fail*
|
||||
*g:matchup_delim_count_fail*
|
||||
|
||||
When enabled, giving an invalid count to the |[%| and |]%| motions will
|
||||
cause the motion to fail. Otherwise they will move as far as possible.
|
||||
When disabled (default), giving an invalid count to the |[%| and |]%| motions
|
||||
and the text objects |i%| and |a%| will cause the motion or operation to fail.
|
||||
When enabled, they will move as far as possible.
|
||||
Note: targeting high counts when this option is enabled can become slow
|
||||
because many positions need to be tried before giving up.
|
||||
|
||||
Default: 1
|
||||
Default: 0
|
||||
|
||||
Module text_obj~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user