X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=vim%2Fmoose_snippets.vim;h=5b97d8d523bc5b24595dad17f561ffe57b982b11;hb=4c82fd0d877189023ee399feda4d75d405bfd124;hp=1c7e7ef9b4fbbfbc26813503f2d9d3c65c75512d;hpb=44a131b366016b80c8ca3b46ddede4df26a5332e;p=gitmo%2Fmoose-dev-utils.git diff --git a/vim/moose_snippets.vim b/vim/moose_snippets.vim index 1c7e7ef..5b97d8d 100644 --- a/vim/moose_snippets.vim +++ b/vim/moose_snippets.vim @@ -1,22 +1,121 @@ " See http://www.vim.org/scripts/script.php?script_id=1318 -" Written by Sartak, feel free to add your own! +" Written by Sartak and doy, feel free to add your own! 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 + if @z == "SuperClass" + s/extends '<{}>';\n\n//e + return "" + endif + + return @z +endfun + +function! RemoveEmptyLine() + s/^\s*<{}>\s*\n//e return @z endfun -exec "Snippet class package ".st."ClassName".et.";use Moose;extends '".st."SuperClass:RemoveEmptySuperClass()".et."';".st.et."__PACKAGE__->meta->make_immutable;no Moose;1;" -exec "Snippet has has ".st."attr".et." => (is => 'rw',isa => '".st."Str".et."',".st.et.");" -exec "Snippet hasl has ".st."attr".et." => (is => 'rw',isa => '".st."Str".et."',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."}" -exec "Snippet around around ".st."name".et." => sub {my $next = shift;my $self = shift;".st.et."};" +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('role', [ + \"package <{RoleName}>;", + \"use Moose::Role;", + \"", + \"<{}>", + \"", + \"no Moose::Role;", + \"", + \"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 $<{next}> = shift;", + \ "my $self = shift;", + \ "<{}>", + \"};"]) +call Snippet('before', [ + \"before <{name}> => sub {", + \ "my $self = shift;", + \ "<{}>", + \"};"]) +call Snippet('after', [ + \"after <{name}> => sub {", + \ "my $self = shift;", + \ "<{}>", + \"};"]) + +" MooseX support +call Snippet('prole', [ + \"package <{RoleName}>;", + \"use MooseX::Role::Parameterized;", + \"", + \"<{}>", + \"", + \"role {", + \"my $p = shift;", + \"", + \"<{}>", + \"};", + \"", + \"no MooseX::Role::Parameterized;", + \"", + \"1;"]) +"for file in globpath(&rtp, 'snippets/*') + "call SnippetFile(file) +"endfor