summaryrefslogtreecommitdiffstats
path: root/vim/after
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-05 00:07:17 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-05 00:07:17 -0500
commit2ca5400cbe5bafc54f59ddedddcd8dc80c510942 (patch)
tree8f008d996ff142e540d421c0a5197dff8f8c9ae4 /vim/after
parent8fd8668473ba98d02122263160b05727e569b189 (diff)
downloadconf-2ca5400cbe5bafc54f59ddedddcd8dc80c510942.tar.gz
conf-2ca5400cbe5bafc54f59ddedddcd8dc80c510942.zip
add moose snippets
Diffstat (limited to 'vim/after')
-rw-r--r--vim/after/ftplugin/moose_snippets.vim86
1 files changed, 86 insertions, 0 deletions
diff --git a/vim/after/ftplugin/moose_snippets.vim b/vim/after/ftplugin/moose_snippets.vim
new file mode 100644
index 0000000..a8c2f69
--- /dev/null
+++ b/vim/after/ftplugin/moose_snippets.vim
@@ -0,0 +1,86 @@
+" See http://www.vim.org/scripts/script.php?script_id=1318
+" Written by Sartak, feel free to add your own!
+
+if !exists('loaded_snippet') || &cp
+ finish
+endif
+
+function RemoveEmptySuperClass()
+ s/^extends '<{}>';\n//e
+ return @z
+endfun
+
+function Snippet(abbr, str)
+ if type(a:str) == type([])
+ return Snippet(a:abbr, join(a:str, "\n"))
+ endif
+ let st = g:snip_start_tag
+ let et = g:snip_end_tag
+ let cd = g:snip_elem_delim
+ let str = substitute(a:str, '<{.\{-}\zs:\ze.\{-}}>', cd, "")
+ let str = substitute(str, '<{', st, "")
+ let str = substitute(str, '}>', et, "")
+ exec 'Snippet '.a:abbr.' '.str
+endfunction
+
+function SnippetFile(filename)
+ let abbr = fnamemodify(a:filename, ':t:r')
+ let str = readfile(a:filename)
+ return Snippet(abbr, str)
+endfunction
+
+call Snippet('class', [
+ \"package <{ClassName}>;",
+ \"use Moose;",
+ \"",
+ \"extends '<{SuperClass:RemoveEmptySuperClass()}>;",
+ \"",
+ \"<{}>",
+ \"",
+ \"__PACKAGE__->meta->make_immutable;",
+ \"no Moose;",
+ \"",
+ \"1;"])
+call Snippet('has', [
+ \"has <{attr}> => (",
+ \ "is => '<{rw}>',",
+ \ "isa => '<{Str}>',",
+ \ "<{}>",
+ \");"])
+call Snippet('hasl', [
+ \"has <{attr}> => (",
+ \ "is => '<{rw}>',",
+ \ "isa => '<{Str}>',",
+ \ "lazy_build => 1,",
+ \ "<{}>",
+ \");",
+ \"",
+ \"sub _build_<{attr}> {",
+ \ "my $self = shift;",
+ \ "<{}>",
+ \"}"])
+call Snippet('sub', [
+ \"sub <{name}> {",
+ \ "my $self = shift;",
+ \ "<{}>",
+ \"}"])
+call Snippet('around', [
+ \"around <{name}> => sub {",
+ \ "my $orig = shift;",
+ \ "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)
+"endfor