1 " See http://www.vim.org/scripts/script.php?script_id=1318
2 " Written by Sartak, feel free to add your own!
4 if !exists('loaded_snippet') || &cp
8 function RemoveEmptySuperClass()
9 s/^extends '<{}>';\n//e
13 function LazyBuilder()
14 let pattern = "has\\s\\+\\zs.\\{-}\\ze\\s\\+=>"
15 let lnum = search(pattern, 'bnW')
16 return matchstr(getline(lnum), pattern)
19 function Snippet(abbr, str)
20 if type(a:str) == type([])
21 return Snippet(a:abbr, join(a:str, "\n"))
23 let st = g:snip_start_tag
24 let et = g:snip_end_tag
25 let cd = g:snip_elem_delim
26 let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "")
27 let str = substitute(str, '<{', st, "")
28 let str = substitute(str, '}>', et, "")
29 exec 'Snippet '.a:abbr.' '.str
32 function SnippetFile(filename)
33 let abbr = fnamemodify(a:filename, ':t:r')
34 let str = readfile(a:filename)
35 return Snippet(abbr, str)
38 call Snippet('class', [
39 \"package <{ClassName}>;",
42 \"extends '<{SuperClass:RemoveEmptySuperClass()}>;",
46 \"__PACKAGE__->meta->make_immutable;",
53 \ "isa => '<{Str}>',",
56 call Snippet('hasl', [
59 \ "isa => '<{Str}>',",
64 \"sub _build_<{attr:LazyBuilder()}> {",
65 \ "my $self = shift;",
70 \ "my $self = shift;",
73 call Snippet('around', [
74 \"around <{name}> => sub {",
75 \ "my $orig = shift;",
76 \ "my $self = shift;",
80 "for file in globpath(&rtp, 'snippets/*')
81 "call SnippetFile(file)