1 " See http://www.vim.org/scripts/script.php?script_id=1318
2 " Written by Sartak and doy, feel free to add your own!
4 if !exists('loaded_snippet') || &cp
8 function! RemoveEmptySuperClass()
10 s/extends '<{}>';\n\n//e
17 function! RemoveEmptyLine()
22 function! Snippet(abbr, str)
23 if type(a:str) == type([])
24 return Snippet(a:abbr, join(a:str, "\n"))
26 let st = g:snip_start_tag
27 let et = g:snip_end_tag
28 let cd = g:snip_elem_delim
29 let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "")
30 let str = substitute(str, '<{', st, "")
31 let str = substitute(str, '}>', et, "")
32 exec 'Snippet '.a:abbr.' '.str
35 function! SnippetFile(filename)
36 let abbr = fnamemodify(a:filename, ':t:r')
37 let str = readfile(a:filename)
38 return Snippet(abbr, str)
41 call Snippet('class', [
42 \"package <{ClassName}>;",
45 \"extends '<{SuperClass:RemoveEmptySuperClass()}>';",
49 \"__PACKAGE__->meta->make_immutable;",
53 call Snippet('role', [
54 \"package <{RoleName}>;",
65 \ "isa => '<{Str}>',",
66 \ "<{options:RemoveEmptyLine()}>",
68 call Snippet('hasl', [
71 \ "isa => '<{Str}>',",
73 \ "<{options:RemoveEmptyLine()}>",
76 \"sub _build_<{attr}> {",
77 \ "my $self = shift;",
82 \ "my $self = shift;",
85 call Snippet('around', [
86 \"around <{name}> => sub {",
87 \ "my $<{next}> = shift;",
88 \ "my $self = shift;",
91 call Snippet('before', [
92 \"before <{name}> => sub {",
93 \ "my $self = shift;",
96 call Snippet('after', [
97 \"after <{name}> => sub {",
98 \ "my $self = shift;",
103 call Snippet('prole', [
104 \"package <{RoleName}>;",
105 \"use MooseX::Role::Parameterized;",
115 \"no MooseX::Role::Parameterized;",
119 "for file in globpath(&rtp, 'snippets/*')
120 "call SnippetFile(file)