The silent! is required to ignore a trigger to search for the last searched pattern. TBH, I'm unable to figure out why this happens.
Thanks to dhruvsagar for suggesting using folddoclosed()
Hey kshenoy, chrisbra10 pointed out the reason why it was triggering the search here on reddit. I've updated my fork of your gist here with the fix accordingly.
function! FoldAllBut( foldminlines )
\ if ( (foldclosed(".") >= 0 ) && ( foldclosedend(".") - foldclosed(".") + 1 < a:foldminlines ))
\ exe "normal! zO"
Posted here just in case.
Ah, works properly now. Updated it at my end as well.