Skip to content

Commit

Permalink
Enforce search behavior for "set foldopen-=search"
Browse files Browse the repository at this point in the history
Sneaking now behaves like / when "foldopen-=search" is set: Closed folds
are considered to be single targets and are not opened when sneaking to
them. They are opened, however, when the default-&foldopen is used or
"foldopen+=search" is set; see a7f59bf.
Resolve justinmk#102.

This does not affect streak-mode (which still ignores &foldopen).
  • Loading branch information
milsen committed Aug 3, 2015
1 parent a7f59bf commit 9ff3a15
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions plugin/sneak.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func! sneak#init()
unlockvar g:sneak#opt
"options v-- for backwards-compatibility
let g:sneak#opt = { 'f_reset' : get(g:, 'sneak#nextprev_f', get(g:, 'sneak#f_reset', 1))
\ ,'t_reset' : get(g:, 'sneak#nextprev_t', get(g:, 'sneak#t_reset', 1))
\ ,'s_next' : get(g:, 'sneak#s_next', 0)
\ ,'absolute_dir' : get(g:, 'sneak#absolute_dir', 0)
\ ,'textobject_z' : get(g:, 'sneak#textobject_z', 1)
\ ,'use_ic_scs' : get(g:, 'sneak#use_ic_scs', 0)
\ ,'map_netrw' : get(g:, 'sneak#map_netrw', 1)
\ ,'streak' : get(g:, 'sneak#streak', 0) && (v:version >= 703) && has("conceal")
\ ,'streak_esc' : get(g:, 'sneak#streak_esc', "\<space>")
\ ,'prompt' : get(g:, 'sneak#prompt', '>')
\ }
\ ,'t_reset' : get(g:, 'sneak#nextprev_t', get(g:, 'sneak#t_reset', 1))
\ ,'s_next' : get(g:, 'sneak#s_next', 0)
\ ,'absolute_dir' : get(g:, 'sneak#absolute_dir', 0)
\ ,'textobject_z' : get(g:, 'sneak#textobject_z', 1)
\ ,'use_ic_scs' : get(g:, 'sneak#use_ic_scs', 0)
\ ,'map_netrw' : get(g:, 'sneak#map_netrw', 1)
\ ,'streak' : get(g:, 'sneak#streak', 0) && (v:version >= 703) && has("conceal")
\ ,'streak_esc' : get(g:, 'sneak#streak_esc', "\<space>")
\ ,'prompt' : get(g:, 'sneak#prompt', '>')
\ }

for k in ['f', 't'] "if user mapped f/t to Sneak, then disable f/t reset.
if maparg(k, 'n') =~# 'Sneak'
Expand Down Expand Up @@ -152,9 +152,19 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
let nudge = sneak#util#nudge(!a:reverse) "special case for t
endif

" detect whether folds should be opened during search according to &foldopen
let l:search_foldopen = !empty(matchstr(&foldopen,"search"))

for i in range(1, max([1, skip])) "jump to the [count]th match
" if in a closed fold, jump to end of it for 'set foldopen-=search'
let l:winview = winsaveview()
if !l:search_foldopen && foldclosed('.') > -1
call cursor(a:reverse ? foldclosed('.') : foldclosedend('.'),
\ a:reverse ? 1 : '$')
endif
let matchpos = s.dosearch()
if 0 == max(matchpos)
if 0 == max(matchpos) " if no search results found
call winrestview(l:winview) " revert jump to end of fold and break
break
else
let nudge = !a:inclusive
Expand All @@ -172,9 +182,9 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
endif
"search succeeded

" if &foldopen contains search, folds are opened when jumping to matches
if !empty(matchstr(&foldopen,"search"))
norm! zv
" open folds when jumping to matches if necessary
if l:search_foldopen
norm! zv
endif

call sneak#hl#removehl()
Expand Down

0 comments on commit 9ff3a15

Please sign in to comment.