Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加each_with_index ,eachdo ,更好的eruby支持 #21

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 42 additions & 25 deletions ftplugin/ruby/ruby.xpt.vim
Expand Up @@ -23,7 +23,7 @@ endfunction "}}}
" Multiple each snippet {{{
"{{{ s:each_list
let s:each_list = [ 'byte', 'char', 'cons', 'index', 'key',
\'line', 'pair', 'slice', 'value' ]
\'line', 'pair', 'slice', 'value' ,'with_index' ]
"}}}

fun! s:f.RubyEachPopup() "{{{
Expand All @@ -49,6 +49,8 @@ fun! s:f.RubyEachPair() "{{{
let v = self.R('what')
if v =~# 'pair'
return '`el1^, `el2^'
elseif v =~# 'with_index'
return '`element^, `index^'
elseif v == ''
return '`el^'
else
Expand All @@ -58,8 +60,16 @@ fun! s:f.RubyEachPair() "{{{
return '`' . substitute(v,'[^a-z]','','g') . '^'
endif
endfunction "}}}

" End multiple each snippet }}}

fun! s:f.ERubyEmbed(embed)
if &filetype == 'eruby'
return a:embed
endif
return ''
endfunction

" Multiple assert snippet {{{
"{{{ s:assert_map
let s:assert_map = {
Expand Down Expand Up @@ -298,17 +308,17 @@ end

XPT case " case .. when .. end
XSET block=# block
case `target^`
when `comparison^
case `target^`ERubyEmbed(' %>')^
`ERubyEmbed('<% ')^when `comparison^`ERubyEmbed(' %>')^
`block^
``when...`
{{^when `comparison^
{{^`ERubyEmbed('<% ')^when `comparison^`ERubyEmbed(' %>')^
`block^
``when...`
^`}}^``else...`
{{^else
{{^`ERubyEmbed('<% ')^else`ERubyEmbed(' %>')^
`cursor^
`}}^end
`}}^`ERubyEmbed('<% ')^end


XPT cfy " classify { |..| .. }
Expand Down Expand Up @@ -439,9 +449,9 @@ Dir.glob(`dir^) { |`file^| `cursor^ }

XPT do " do |..| .. end
XSET arg*|post=RepeatInsideEdges(', ')
do` |`arg*`|^
do` |`arg*`|^`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end


XPT dow " downto\(..) { .. }
Expand All @@ -456,6 +466,13 @@ XSET what|post=RubyEachBrace()
XSET vars=RubyEachPair()
each`_`what^ { |`vars^| `cursor^ }

XPT eachdo " each_** do .. end
XSET what=RubyEachPopup()
XSET what|post=RubyEachBrace()
XSET vars=RubyEachPair()
each`_`what^ do |`vars^|`ERubyEmbed(' %>')^
`cursor^
`ERubyEmbed('<% ')^end

XPT fdir " File.dirname\(..)
File.dirname(`^)
Expand Down Expand Up @@ -501,30 +518,30 @@ XPT hash " Hash.new { ... }
Hash.new { |`hash^,`key^| `hash^[`key^] = `cursor^ }

XPT if " if .. end
if `boolean exp^
if `boolean exp^`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end

XPT ife " if .. else .. end
XSET block=# block
if `boolean exp^
if `boolean exp^`ERubyEmbed(' %>')^
`block^
else
`ERubyEmbed('<% ')^else`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end

XPT ifei " if .. elsif .. else .. end
XSET block=# block
if `boolean exp^`
if `boolean exp^`ERubyEmbed(' %>')^`
`block^
``elsif...`
{{^elsif `comparison^
{{^`ERubyEmbed('<% ')^elsif `comparison^`ERubyEmbed(' %>')^
`block^
``elsif...`
^`}}^``else...`
{{^else
{{^`ERubyEmbed('<% ')^else`ERubyEmbed(' %>')^
`cursor^
`}}^end
`}}^`ERubyEmbed('<% ')^end


XPT inj " inject\(..) { |..| .. }
Expand All @@ -537,9 +554,9 @@ lambda {` |`arg*`|^ `cursor^ }


XPT loop " loop do ... end
loop do
loop do`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end

XPT map " map { |..| .. }
map { |`arg^| `cursor^ }
Expand Down Expand Up @@ -718,15 +735,15 @@ end


XPT unless " unless .. end
unless `boolean cond^
unless `boolean cond^`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end


XPT until " until .. end
until `boolean cond^
until `boolean cond^`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end


XPT upt " upto\(..) { .. }
Expand All @@ -748,9 +765,9 @@ end


XPT while " while .. end
while `boolean cond^
while `boolean cond^`ERubyEmbed(' %>')^
`cursor^
end
`ERubyEmbed('<% ')^end


XPT wid " with_index { .. }
Expand Down