" See http://www.vim.org/scripts/script.php?script_id=1318 " Written by Sartak and doy, feel free to add your own! if !exists('loaded_snippet') || &cp finish endif function! RemoveUnchangedLine() if match(getline('.'), "<{}>") >= 0 normal! dd return '' else return @z endif endfun function! RemoveUnchangedLineSemicolon() if match(getline('.'), "<{}>") >= 0 normal! ddkA; normal! o return '' else normal! A; "normal! o " we can't actually change what line we're on :/ return @z endif 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 function! ParameterizedModule() let current_file = expand("%") let t = substitute(current_file, '\.pm', '', '') let t = substitute(t, 'lib/', '', '') " Sadly, this does not work because : is a special character in snippet " tag names. Any ideas? "let module = substitute(t, '/', '::', 'g') let module = substitute(t, '/.*', '', '') return '<{' . module . '}>' endfun call Snippet('class', [ \"package ".ParameterizedModule().";", \"use Moose;", \"extends '<{SuperClass:RemoveUnchangedLine()}>';", \"", \"<{}>", \"", \"__PACKAGE__->meta->make_immutable;", \"no Moose;", \"", \"1;"]) call Snippet('role', [ \"package ".ParameterizedModule().";", \"use Moose::Role;", \"", \"<{}>", \"", \"no Moose::Role;", \"", \"1;"]) call Snippet('has', [ \"has <{attr}> => (", \ "is => '<{rw}>',", \ "isa => '<{Str}>',", \ "<{options:RemoveUnchangedLine()}>", \");"]) call Snippet('hasl', [ \"has <{attr}> => (", \ "is => '<{rw}>',", \ "isa => '<{Str}>',", \ "lazy_build => 1,", \ "<{options:RemoveUnchangedLine()}>", \");", \"", \"sub _build_<{attr}> {", \ "my $self = shift;", \ "<{}>", \"}"]) call Snippet('sub', [ \"sub <{name}> {", \ "my $self = shift;", \ "my (<{arg:RemoveUnchangedLine()}>) = @_;", \ "<{}>", \"}"]) call Snippet('around', [ \"around <{name}> => sub {", \ "my $<{next}> = shift;", \ "my $self = shift;", \ "<{}>", \"};"]) call Snippet('before', [ \"before <{name}> => sub {", \ "my $self = shift;", \ "<{}>", \"};"]) call Snippet('after', [ \"after <{name}> => sub {", \ "my $self = shift;", \ "<{}>", \"};"]) call Snippet('subtype', [ \"subtype '<{name}>'", \ "=> as '<{supertype}>'", \ "=> where { <{predicate:RemoveUnchangedLine()}> }", \ "=> message { \"<{message:RemoveUnchangedLineSemicolon()}>\" }", \""]) " MooseX support call Snippet('prole', [ \"package ".ParameterizedModule().";", \"use MooseX::Role::Parameterized;", \"", \"<{}>", \"", \"role {", \"my $p = shift;", \"", \"<{}>", \"};", \"", \"no MooseX::Role::Parameterized;", \"", \"1;"]) "for file in globpath(&rtp, 'snippets/*') "call SnippetFile(file) "endfor