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()
9 s/^extends '<{}>';\n//e
13 function! RemoveEmptyLine()
18 function! Snippet(abbr, str)
19 if type(a:str) == type([])
20 return Snippet(a:abbr, join(a:str, "\n"))
22 let st = g:snip_start_tag
23 let et = g:snip_end_tag
24 let cd = g:snip_elem_delim
25 let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "")
26 let str = substitute(str, '<{', st, "")
27 let str = substitute(str, '}>', et, "")
28 exec 'Snippet '.a:abbr.' '.str
31 function! SnippetFile(filename)
32 let abbr = fnamemodify(a:filename, ':t:r')
33 let str = readfile(a:filename)
34 return Snippet(abbr, str)
37 call Snippet('class', [
38 \"package <{ClassName}>;",
41 \"extends '<{SuperClass:RemoveEmptySuperClass()}>;",
45 \"__PACKAGE__->meta->make_immutable;",
52 \ "isa => '<{Str}>',",
53 \ "<{options:RemoveEmptyLine()}>",
55 call Snippet('hasl', [
58 \ "isa => '<{Str}>',",
60 \ "<{options:RemoveEmptyLine()}>",
63 \"sub _build_<{attr}> {",
64 \ "my $self = shift;",
69 \ "my $self = shift;",
72 call Snippet('around', [
73 \"around <{name}> => sub {",
74 \ "my $orig = shift;",
75 \ "my $self = shift;",
78 call Snippet('before', [
79 \"before <{name}> => sub {",
80 \ "my $self = shift;",
83 call Snippet('after', [
84 \"after <{name}> => sub {",
85 \ "my $self = shift;",
89 "for file in globpath(&rtp, 'snippets/*')
90 "call SnippetFile(file)