Skip to content

Commit efa55ac

Browse files
committed
Add do begin case foldable_groups options
Put there simple blocks into one `blocks` example.
1 parent f6742e6 commit efa55ac

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

doc/ft-ruby-syntax.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ value is space-separated keywords, known keywords were:
5959
def "def" block
6060
class "class" block
6161
module "module" block
62-
case "case" block
6362
do "do" block
63+
begin "begin" block
64+
case "case" block
6465
% Literal with "%" notation, e.g.: %w(STRING), %!STRING!
6566
/ Regexp
6667
string String and shell command output (surrounded by ', ", `)

etc/examples/generators/syntax/percent_generator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@
363363

364364

365365

366-
# def {{{
367-
# rubyMethodBlock and rubyBlock
368-
if arg == 'def'
366+
# blocks {{{
367+
# simple blocks (def, class, module, do, begin, case)
368+
if arg == 'blocks'
369369
puts <<-END.gsub(/^\s{4}/, '')
370370
def
371371
foo
@@ -377,7 +377,7 @@
377377
378378
END
379379

380-
%w(class module).each do |s|
380+
%w(class module do begin case).each do |s|
381381
puts <<-END.gsub(/^\s{6}/, '')
382382
#{s}
383383
foo
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by `./etc/examples/generators/syntax/percent_generator.rb def > etc/examples/syntax/percent/def.rb`
1+
# Generated by `./etc/examples/generators/syntax/percent_generator.rb blocks > etc/examples/syntax/percent/blocks.rb`
22

33
def
44
foo
@@ -18,4 +18,19 @@
1818
end
1919

2020

21+
do
22+
foo
23+
end
24+
25+
26+
begin
27+
foo
28+
end
29+
30+
31+
case
32+
foo
33+
end
34+
35+
2136
# vim:foldmethod=syntax

syntax/ruby.vim

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)