better remove empty line function
Jesse Luehrs [Tue, 12 May 2009 03:44:47 +0000 (22:44 -0500)]
vim/moose_snippets.vim

index ae377a6..bfe9f90 100644 (file)
@@ -5,18 +5,13 @@ if !exists('loaded_snippet') || &cp
     finish
 endif
 
-function! RemoveEmptySuperClass()
-    if @z == "SuperClass"
-        s/extends '<{}>';\n\n//e
-        return ""
+function! RemoveUnchangedLine()
+    if match(getline('.'), "<{}>") >= 0
+        normal! dd
+        return ''
+    else
+        return @z
     endif
-
-    return @z
-endfun
-
-function! RemoveEmptyLine()
-    s/^\s*<{}>\s*\n//e
-    return @z
 endfun
 
 function! Snippet(abbr, str)
@@ -55,7 +50,7 @@ call Snippet('class', [
             \"package ".ParameterizedModule().";",
             \"use Moose;",
             \"",
-            \"extends '<{SuperClass:RemoveEmptySuperClass()}>';",
+            \"extends '<{SuperClass:RemoveUnchangedLine()}>;",
             \"",
             \"<{}>",
             \"",
@@ -76,14 +71,14 @@ call Snippet('has', [
             \"has <{attr}> => (",
             \    "is  => '<{rw}>',",
             \    "isa => '<{Str}>',",
-            \    "<{options:RemoveEmptyLine()}>",
+            \    "<{options:RemoveUnchangedLine()}>",
             \");"])
 call Snippet('hasl', [
             \"has <{attr}> => (",
             \    "is         => '<{rw}>',",
             \    "isa        => '<{Str}>',",
             \    "lazy_build => 1,",
-            \    "<{options:RemoveEmptyLine()}>",
+            \    "<{options:RemoveUnchangedLine()}>",
             \");",
             \"",
             \"sub _build_<{attr}> {",
@@ -93,6 +88,7 @@ call Snippet('hasl', [
 call Snippet('sub', [
             \"sub <{name}> {",
             \    "my $self = shift;",
+            \    "my (<{arg:RemoveUnchangedLine()}>) = @_;",
             \    "<{}>",
             \"}"])
 call Snippet('around', [