X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=vim%2Fmoose_snippets.vim;h=d69c740067d994953e10a0dc786b13e4d1222f4e;hb=413489996b3da5da6999b39a599e81776f679a0a;hp=750206e2235f57c49970dd1d6b6c4c1b3702435b;hpb=9ac2672c3469e81b568d2d15397290770ecea350;p=gitmo%2Fmoose-dev-utils.git diff --git a/vim/moose_snippets.vim b/vim/moose_snippets.vim index 750206e..d69c740 100644 --- a/vim/moose_snippets.vim +++ b/vim/moose_snippets.vim @@ -1,22 +1,21 @@ " 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 -function RemoveEmptySuperClass() +function! RemoveEmptySuperClass() s/^extends '<{}>';\n//e return @z endfun -function LazyBuilder() - let pattern = "has\\s\\+\\zs.\\{-}\\ze\\s\\+=>" - let lnum = search(pattern, 'bnW') - return matchstr(getline(lnum), pattern) -endfunction +function! RemoveEmptyLine() + s/^\s*<{}>\s*\n//e + return @z +endfun -function Snippet(abbr, str) +function! Snippet(abbr, str) if type(a:str) == type([]) return Snippet(a:abbr, join(a:str, "\n")) endif @@ -29,7 +28,7 @@ function Snippet(abbr, str) exec 'Snippet '.a:abbr.' '.str endfunction -function SnippetFile(filename) +function! SnippetFile(filename) let abbr = fnamemodify(a:filename, ':t:r') let str = readfile(a:filename) return Snippet(abbr, str) @@ -47,21 +46,30 @@ call Snippet('class', [ \"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:LazyBuilder()}> {", + \"sub _build_<{attr}> {", \ "my $self = shift;", \ "<{}>", \"}"]) @@ -72,7 +80,7 @@ call Snippet('sub', [ \"}"]) call Snippet('around', [ \"around <{name}> => sub {", - \ "my $orig = shift;", + \ "my $<{next}> = shift;", \ "my $self = shift;", \ "<{}>", \"};"]) @@ -87,6 +95,23 @@ call Snippet('after', [ \ "<{}>", \"};"]) +" 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