@@ -18,16 +18,16 @@ func! sneak#init()
1818 unlockvar g: sneak #opt
1919 " options v-- for backwards-compatibility
2020 let g: sneak #opt = { ' f_reset' : get (g: , ' sneak#nextprev_f' , get (g: , ' sneak#f_reset' , 1 ))
21- \ ,' t_reset' : get (g: , ' sneak#nextprev_t' , get (g: , ' sneak#t_reset' , 1 ))
22- \ ,' s_next' : get (g: , ' sneak#s_next' , 0 )
23- \ ,' absolute_dir' : get (g: , ' sneak#absolute_dir' , 0 )
24- \ ,' textobject_z' : get (g: , ' sneak#textobject_z' , 1 )
25- \ ,' use_ic_scs' : get (g: , ' sneak#use_ic_scs' , 0 )
26- \ ,' map_netrw' : get (g: , ' sneak#map_netrw' , 1 )
27- \ ,' streak' : get (g: , ' sneak#streak' , 0 ) && (v: version >= 703 ) && has (" conceal" )
28- \ ,' streak_esc' : get (g: , ' sneak#streak_esc' , " \<space> " )
29- \ ,' prompt' : get (g: , ' sneak#prompt' , ' >' )
30- \ }
21+ \ ,' t_reset' : get (g: , ' sneak#nextprev_t' , get (g: , ' sneak#t_reset' , 1 ))
22+ \ ,' s_next' : get (g: , ' sneak#s_next' , 0 )
23+ \ ,' absolute_dir' : get (g: , ' sneak#absolute_dir' , 0 )
24+ \ ,' textobject_z' : get (g: , ' sneak#textobject_z' , 1 )
25+ \ ,' use_ic_scs' : get (g: , ' sneak#use_ic_scs' , 0 )
26+ \ ,' map_netrw' : get (g: , ' sneak#map_netrw' , 1 )
27+ \ ,' streak' : get (g: , ' sneak#streak' , 0 ) && (v: version >= 703 ) && has (" conceal" )
28+ \ ,' streak_esc' : get (g: , ' sneak#streak_esc' , " \<space> " )
29+ \ ,' prompt' : get (g: , ' sneak#prompt' , ' >' )
30+ \ }
3131
3232 for k in [' f' , ' t' ] " if user mapped f/t to Sneak, then disable f/t reset.
3333 if maparg (k , ' n' ) = ~# ' Sneak'
@@ -152,9 +152,19 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
152152 let nudge = sneak#util#nudge (! a: reverse ) " special case for t
153153 endif
154154
155+ " detect whether folds should be opened during search according to &foldopen
156+ let l: search_foldopen = ! empty (matchstr (&foldopen ," search" ))
157+
155158 for i in range (1 , max ([1 , skip ])) " jump to the [count]th match
159+ " if in a closed fold, jump to end of it for 'set foldopen-=search'
160+ let l: winview = winsaveview ()
161+ if ! l: search_foldopen && foldclosed (' .' ) > -1
162+ call cursor (a: reverse ? foldclosed (' .' ) : foldclosedend (' .' ),
163+ \ a: reverse ? 1 : ' $' )
164+ endif
156165 let matchpos = s .dosearch ()
157- if 0 == max (matchpos)
166+ if 0 == max (matchpos) " if no search results found
167+ call winrestview (l: winview ) " revert jump to end of fold and break
158168 break
159169 else
160170 let nudge = ! a: inclusive
@@ -172,9 +182,9 @@ func! sneak#to(op, input, inputlen, count, repeatmotion, reverse, inclusive, str
172182 endif
173183 " search succeeded
174184
175- " if &foldopen contains search, folds are opened when jumping to matches
176- if ! empty ( matchstr (& foldopen , " search " ))
177- norm! zv
185+ " open folds when jumping to matches if necessary
186+ if l: search_foldopen
187+ norm! zv
178188 endif
179189
180190 call sneak#hl#removehl ()
0 commit comments