X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=vim%2Fmoose_snippets.vim;h=50aa99fba07378a01ae05432f371f0dee7c02771;hb=f93358a2f9a3bca29868c74af9f3dff56ff8cf6d;hp=67a835dac0c51e386630c2b5ca89ab52c46e9ad6;hpb=9e14e28f32e3ece43fab98e4fec94d6502c36914;p=gitmo%2Fmoose-dev-utils.git diff --git a/vim/moose_snippets.vim b/vim/moose_snippets.vim index 67a835d..50aa99f 100644 --- a/vim/moose_snippets.vim +++ b/vim/moose_snippets.vim @@ -5,18 +5,17 @@ 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) @@ -51,17 +50,17 @@ 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;", \ "<{}>", \"}"]) @@ -76,6 +75,16 @@ call Snippet('around', [ \ "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)