s/$orig/<{$next}>/ :)
[gitmo/moose-dev-utils.git] / vim / moose_snippets.vim
CommitLineData
bb2ea7b7 1" See http://www.vim.org/scripts/script.php?script_id=1318
9f4e6b22 2" Written by Sartak and doy, feel free to add your own!
bb2ea7b7 3
4if !exists('loaded_snippet') || &cp
5 finish
6endif
7
f93358a2 8function! RemoveEmptySuperClass()
9a5242eb 9 s/^extends '<{}>';\n//e
10 return @z
11endfun
12
f93358a2 13function! RemoveEmptyLine()
a55ef827 14 s/^\s*<{}>\s*\n//e
15 return @z
16endfun
17
f93358a2 18function! Snippet(abbr, str)
9e14e28f 19 if type(a:str) == type([])
20 return Snippet(a:abbr, join(a:str, "\n"))
21 endif
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
29endfunction
30
f93358a2 31function! SnippetFile(filename)
9e14e28f 32 let abbr = fnamemodify(a:filename, ':t:r')
33 let str = readfile(a:filename)
34 return Snippet(abbr, str)
35endfunction
36
37call Snippet('class', [
38 \"package <{ClassName}>;",
39 \"use Moose;",
40 \"",
41 \"extends '<{SuperClass:RemoveEmptySuperClass()}>;",
42 \"",
43 \"<{}>",
44 \"",
45 \"__PACKAGE__->meta->make_immutable;",
46 \"no Moose;",
47 \"",
48 \"1;"])
49call Snippet('has', [
50 \"has <{attr}> => (",
51 \ "is => '<{rw}>',",
52 \ "isa => '<{Str}>',",
a55ef827 53 \ "<{options:RemoveEmptyLine()}>",
9e14e28f 54 \");"])
55call Snippet('hasl', [
56 \"has <{attr}> => (",
57 \ "is => '<{rw}>',",
58 \ "isa => '<{Str}>',",
59 \ "lazy_build => 1,",
a55ef827 60 \ "<{options:RemoveEmptyLine()}>",
9e14e28f 61 \");",
62 \"",
a75bdf8d 63 \"sub _build_<{attr}> {",
9e14e28f 64 \ "my $self = shift;",
65 \ "<{}>",
66 \"}"])
67call Snippet('sub', [
68 \"sub <{name}> {",
69 \ "my $self = shift;",
70 \ "<{}>",
71 \"}"])
72call Snippet('around', [
73 \"around <{name}> => sub {",
babbac06 74 \ "my $<{next}> = shift;",
9e14e28f 75 \ "my $self = shift;",
76 \ "<{}>",
77 \"};"])
9ac2672c 78call Snippet('before', [
79 \"before <{name}> => sub {",
80 \ "my $self = shift;",
81 \ "<{}>",
82 \"};"])
83call Snippet('after', [
84 \"after <{name}> => sub {",
85 \ "my $self = shift;",
86 \ "<{}>",
87 \"};"])
bb2ea7b7 88
9e14e28f 89"for file in globpath(&rtp, 'snippets/*')
90 "call SnippetFile(file)
91"endfor