@@ -351,14 +351,29 @@ if !exists("b:ruby_no_expensive") && !exists("ruby_no_expensive")
351351 syn match rubyConditionalModifier " \<\% (if\| unless\)\> " display
352352 syn match rubyRepeatModifier " \<\% (while\| until\)\> " display
353353
354- syn region rubyDoBlock matchgroup =rubyControl start =" \< do\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop fold
354+ if s: foldable (' do' )
355+ syn region rubyDoBlock matchgroup =rubyControl start =" \< do\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop fold
356+ else
357+ syn region rubyDoBlock matchgroup =rubyControl start =" \< do\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop
358+ endif
359+
355360 " curly bracket block or hash literal
356361 syn region rubyCurlyBlock matchgroup =rubyCurlyBlockDelimiter start =" {" end =" }" contains =ALLBUT,@rubyNotTop fold
357362 syn region rubyArrayLiteral matchgroup =rubyArrayDelimiter start =" \% (\w\| [\] })]\)\@ <!\[ " end =" ]" contains =ALLBUT,@rubyNotTop fold
358363
359364 " statements without 'do'
360- syn region rubyBlockExpression matchgroup =rubyControl start =" \< begin\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop fold
361- syn region rubyCaseExpression matchgroup =rubyConditional start =" \< case\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop fold
365+ if s: foldable (' begin' )
366+ syn region rubyBlockExpression matchgroup =rubyControl start =" \< begin\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop fold
367+ else
368+ syn region rubyBlockExpression matchgroup =rubyControl start =" \< begin\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop
369+ endif
370+
371+ if s: foldable (' case' )
372+ syn region rubyCaseExpression matchgroup =rubyConditional start =" \< case\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop fold
373+ else
374+ syn region rubyCaseExpression matchgroup =rubyConditional start =" \< case\> " end =" \< end\> " contains =ALLBUT,@rubyNotTop
375+ endif
376+
362377 syn region rubyConditionalExpression matchgroup =rubyConditional start =" \% (\% (^\|\.\.\.\=\| [{:,;([<>~\* %&^|+=-]\|\% (\< [_[:lower:]][_[:alnum:]]*\)\@ <![?!]\)\s *\)\@ <=\% (\\\n\s *\)\@ <!\% (if\| unless\)\> " end="\% (\% (\% (\.\@ <!\.\)\| ::\)\s *\)\@ <!\< end\> " contains=ALLBUT,@rubyNotTop fold
363378
364379 syn match rubyConditional " \<\% (then\| else\| when\)\> [?!]\@ !" contained containedin =rubyCaseExpression
0 commit comments