X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=vim%2Fmoose_snippets.vim;h=4f9a8c1b20cfd8299b8f18f24927c4a165a271fd;hb=a55ef8276f4969ab07641f8cb569bf863b2c4786;hp=541f05bc5efdb853a5c380cf705837acf9160ea8;hpb=6166b805b888a1d79f7897940b1b4fc07d94ea19;p=gitmo%2Fmoose-dev-utils.git diff --git a/vim/moose_snippets.vim b/vim/moose_snippets.vim index 541f05b..4f9a8c1 100644 --- a/vim/moose_snippets.vim +++ b/vim/moose_snippets.vim @@ -5,12 +5,87 @@ if !exists('loaded_snippet') || &cp finish endif -let st = g:snip_start_tag -let et = g:snip_end_tag -let cd = g:snip_elem_delim +function RemoveEmptySuperClass() + s/^extends '<{}>';\n//e + return @z +endfun -exec "Snippet class package ".st."ClassName".et.";use Moose;extends '".st."SuperClass".et."';".st.et."__PACKAGE__->meta->make_immutable;no Moose;1;" -exec "Snippet has has ".st."attr".et." => (is => 'rw',isa => 'Str',".st.et.");" -exec "Snippet hasl has ".st."attr".et." => (is => 'rw',isa => 'Str',lazy_build => 1,);sub _build_".st."attr".et." {my $self = shift;".st.et."}" -exec "Snippet sub sub ".st."name".et." {my $self = shift;".st.et."}" +function RemoveEmptyLine() + s/^\s*<{}>\s*\n//e + return @z +endfun +function Snippet(abbr, str) + if type(a:str) == type([]) + return Snippet(a:abbr, join(a:str, "\n")) + endif + let st = g:snip_start_tag + let et = g:snip_end_tag + let cd = g:snip_elem_delim + let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "") + let str = substitute(str, '<{', st, "") + let str = substitute(str, '}>', et, "") + exec 'Snippet '.a:abbr.' '.str +endfunction + +function SnippetFile(filename) + let abbr = fnamemodify(a:filename, ':t:r') + let str = readfile(a:filename) + return Snippet(abbr, str) +endfunction + +call Snippet('class', [ + \"package <{ClassName}>;", + \"use Moose;", + \"", + \"extends '<{SuperClass:RemoveEmptySuperClass()}>;", + \"", + \"<{}>", + \"", + \"__PACKAGE__->meta->make_immutable;", + \"no Moose;", + \"", + \"1;"]) +call Snippet('has', [ + \"has <{attr}> => (", + \ "is => '<{rw}>',", + \ "isa => '<{Str}>',", + \ "<{options:RemoveEmptyLine()}>", + \");"]) +call Snippet('hasl', [ + \"has <{attr}> => (", + \ "is => '<{rw}>',", + \ "isa => '<{Str}>',", + \ "lazy_build => 1,", + \ "<{options:RemoveEmptyLine()}>", + \");", + \"", + \"sub _build_<{attr}> {", + \ "my $self = shift;", + \ "<{}>", + \"}"]) +call Snippet('sub', [ + \"sub <{name}> {", + \ "my $self = shift;", + \ "<{}>", + \"}"]) +call Snippet('around', [ + \"around <{name}> => sub {", + \ "my $orig = shift;", + \ "my $self = shift;", + \ "<{}>", + \"};"]) +call Snippet('before', [ + \"before <{name}> => sub {", + \ "my $self = shift;", + \ "<{}>", + \"};"]) +call Snippet('after', [ + \"after <{name}> => sub {", + \ "my $self = shift;", + \ "<{}>", + \"};"]) + +"for file in globpath(&rtp, 'snippets/*') + "call SnippetFile(file) +"endfor