From 344ac6ea2cc41f83ea8b040f98a0a01bfe64077f Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Sun, 23 Jun 2013 02:30:26 +0200 Subject: [PATCH] new policies for if, eif, el What about wh(ile)? drop some placeholder comments which don't add (enough) value to keep for patterns used very often. --- README.md | 37 ++++++++++++++++ UltiSnips/coffee.snippets | 2 +- UltiSnips/d.snippets | 2 +- UltiSnips/django.snippets | 2 +- UltiSnips/eruby.snippets | 2 +- UltiSnips/haskell.snippets | 8 ++-- UltiSnips/java.snippets | 2 +- UltiSnips/javascript.snippets | 11 ++++- UltiSnips/ocaml.snippets | 81 ++++++++++++++++------------------- UltiSnips/php.snippets | 22 +++++----- UltiSnips/tcl.snippets | 6 +-- UltiSnips/vim.snippets | 16 +++---- snippets/autoit.snippets | 6 +-- snippets/coffee.snippets | 2 +- snippets/falcon.snippets | 2 +- snippets/htmldjango.snippets | 4 +- snippets/htmltornado.snippets | 4 +- snippets/java.snippets | 2 +- snippets/mako.snippets | 2 +- snippets/perl.snippets | 36 +++++++++------- snippets/php.snippets | 4 +- snippets/puppet.snippets | 2 +- snippets/ruby.snippets | 2 +- snippets/scala.snippets | 6 ++- snippets/tcl.snippets | 18 +++++--- snippets/vim.snippets | 14 ++++-- snippets/zsh.snippets | 2 +- 27 files changed, 177 insertions(+), 120 deletions(-) diff --git a/README.md b/README.md index 984cdb6..849d066 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,43 @@ of the snippets by setting the "always_use_first_snippet" option to 1. If you have VimL only (vim without python support) your best option is using garbas/vim-snipmate and cope with the minor bugs found in the engine. + +Policies / for contributors +=========================== +some snippets are useful for all languages, so let's try to have the same +triggers for all languages: + +``` +if : if without else +ife: if $1 else $2 +eif : else if ($1) { .. } +el : else .. +``` + +If you're not satisfied with these defaults, open a ticket that we implement +aliasing. Then you can remap "else" to "el" or the like. + + +Don't add stupid placeholder default texts like +``` +if (${1:condition){ + ${2:some code here} +} +``` +instead use: + +``` +if (${1){ + ${2} +} +``` + +Exception: Functions which are used less often, such as Vim's matchall(), matchstr() +functions which case hints may be helpful to remember order. In the VimL case +get vim-dev plugin which has function completion + +Thus for conditions (while, if ..) and block bodies just use ${N} - Thanks + Related repositories ==================== We also encourage people to maintain sets of snippets for particular use cases diff --git a/UltiSnips/coffee.snippets b/UltiSnips/coffee.snippets index bb451aa..68d4034 100644 --- a/UltiSnips/coffee.snippets +++ b/UltiSnips/coffee.snippets @@ -22,7 +22,7 @@ else ${3:# body...} endsnippet -snippet elif "Else if" b +snippet eif "Else if" b else if ${1:condition} ${0:# body...} endsnippet diff --git a/UltiSnips/d.snippets b/UltiSnips/d.snippets index 8ed9b41..9495951 100644 --- a/UltiSnips/d.snippets +++ b/UltiSnips/d.snippets @@ -126,7 +126,7 @@ else } endsnippet -snippet elif "else if (elif)" b +snippet eif "else if (elif)" b else if(${1:/*condition*/}) { ${VISUAL}${0:/*code*/} diff --git a/UltiSnips/django.snippets b/UltiSnips/django.snippets index 59b77c5..553baba 100644 --- a/UltiSnips/django.snippets +++ b/UltiSnips/django.snippets @@ -76,7 +76,7 @@ snippet if {% endif %} endsnippet -snippet else +snippet el {% else %} ${1} endsnippet diff --git a/UltiSnips/eruby.snippets b/UltiSnips/eruby.snippets index c6b201e..88f7179 100644 --- a/UltiSnips/eruby.snippets +++ b/UltiSnips/eruby.snippets @@ -263,7 +263,7 @@ snippet st "submit_tag" `!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`submit_tag "${1:Save changes}"${2:, :id => "${3:submit}"}${4:, :name => "${5:$3}"}${6:, :class => "${7:form_$3}"}${8:, :disabled => ${9:false}}${10:, :disable_with => "${11:Please wait...}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)` endsnippet -snippet else "else (ERB)" +snippet el "else (ERB)" <% else %> endsnippet diff --git a/UltiSnips/haskell.snippets b/UltiSnips/haskell.snippets index eb7b2c6..99f947f 100644 --- a/UltiSnips/haskell.snippets +++ b/UltiSnips/haskell.snippets @@ -1,13 +1,13 @@ -snippet if "if ... then ... else ..." +snippet ife "if ... then ... else ..." if ${1:condition} then ${2:expression} else ${3:expression} endsnippet snippet case "case ... of ..." -case ${1:expression} of - ${2:pattern} -> ${3:expression} - ${4:pattern} -> ${5:expression} +case ${1} of + ${2} -> ${3} + ${4} -> ${5} endsnippet snippet :: "Type signature" diff --git a/UltiSnips/java.snippets b/UltiSnips/java.snippets index 6e1b3ff..617c161 100644 --- a/UltiSnips/java.snippets +++ b/UltiSnips/java.snippets @@ -59,7 +59,7 @@ default: $0 endsnippet -snippet elif "else if" b +snippet eif "else if" b else if ($1)`!p nl(snip)`{ $0 } diff --git a/UltiSnips/javascript.snippets b/UltiSnips/javascript.snippets index e4e7f7a..7eb18d7 100644 --- a/UltiSnips/javascript.snippets +++ b/UltiSnips/javascript.snippets @@ -50,12 +50,19 @@ function ${1:function_name} (${2:argument}) { } endsnippet +# for one line if .. else you usually use a ? b : c snippet ife "if ___ else" -if (${1:true}) {$0} else{}; +if (${1}) { + {$2} +} else { + {$3} +}; endsnippet snippet if "if" -if (${1:true}) {$0}; +if (${1}) { + {$2} +}; endsnippet snippet timeout "setTimeout function" diff --git a/UltiSnips/ocaml.snippets b/UltiSnips/ocaml.snippets index 8aefef3..14926c8 100644 --- a/UltiSnips/ocaml.snippets +++ b/UltiSnips/ocaml.snippets @@ -4,17 +4,17 @@ endsnippet snippet open "open" let open ${1:module} in -${2:e} +${2} endsnippet snippet try "try" -try ${1:e} +try ${1} with ${2:Not_found} -> ${3:()} endsnippet snippet ref "ref" -let ${1:name} = ref ${2:val} in -${3:e} +let ${1} = ref ${2} in +${3} endsnippet snippet matchl "pattern match on a list" @@ -24,88 +24,83 @@ match ${1:list} with endsnippet snippet matcho "pattern match on an option type" -match ${1:x} with -| Some(${2:y}) -> ${3:()} +match ${1} with +| Some(${2}) -> ${3:()} | None -> ${4:()} endsnippet snippet fun "anonymous function" -(fun ${1:x} -> ${2:x}) +(fun ${1} -> ${2}) endsnippet snippet cc "commment" -(* ${1:comment} *) +(* ${1} *) endsnippet snippet let "let .. in binding" -let ${1:x} = ${2:v} in -${3:e} +let ${1} = ${2} in +${3} endsnippet snippet lr "let rec" -let rec ${1:f} = - ${2:expr} +let rec ${1} = + ${2} endsnippet -snippet if "if" -if ${1:(* condition *)} then - ${2:(* A *)} +snippet ife "if" +if ${1} then + ${2} else - ${3:(* B *)} + ${3} endsnippet -snippet If "If" -if ${1:(* condition *)} then - ${2:(* A *)} +snippet if "If" +if ${1} then + ${2} endsnippet snippet while "while" -while ${1:(* condition *)} do - ${2:(* A *)} +while ${1} do + ${2} done endsnippet snippet for "for" for ${1:i} = ${2:1} to ${3:10} do - ${4:(* BODY *)} + ${4} done endsnippet snippet match "match" -match ${1:(* e1 *)} with -| ${2:p} -> ${3:e2} -endsnippet - -snippet Match "match" -match ${1:(* e1 *)} with -| ${2:p} -> ${3:e2} +match ${1} with +| ${2} -> ${3} endsnippet snippet class "class" class ${1:name} = object - ${2:methods} + ${2} end endsnippet snippet obj "obj" object - ${2:methods} + ${2} end endsnippet snippet Obj "object" object (self) - ${2:methods} + ${2} end endsnippet snippet {{ "object functional update" -{< ${1:x} = ${2:y} >} +{< ${1} = ${2} >} endsnippet snippet beg "beg" begin - ${1:block} + ${1}${VISUAL} end endsnippet @@ -115,19 +110,19 @@ endsnippet snippet mod "module - no signature" module ${1:(* Name *)} = struct - ${2:(* BODY *)} + ${2} end endsnippet snippet Mod "module with signature" module ${1:(* Name *)} : ${2:(* SIG *)} = struct - ${3:(* BODY *)} + ${3} end endsnippet snippet sig "anonymous signature" sig - ${2:(* BODY *)} + ${2} end endsnippet @@ -137,32 +132,32 @@ endsnippet snippet func "define functor - no signature" module ${1:M} (${2:Arg} : ${3:ARG}) = struct - ${4:(* BODY *)} + ${4} end endsnippet snippet Func "define functor - with signature" module ${1:M} (${2:Arg} : ${3:ARG}) : ${4:SIG} = struct - ${5:(* BODY *)} + ${5} end endsnippet snippet mot "Declare module signature" module type ${1:(* Name *)} = sig - ${2:(* BODY *)} + ${2} end endsnippet snippet module "Module with anonymous signature" module ${1:(* Name *)} : sig - ${2:(* SIGNATURE *)} + ${2} end = struct - ${3:(* BODY *)} + ${3} end endsnippet snippet oo "odoc" -(** ${1:odoc} *) +(** ${1} *) endsnippet snippet qt "inline qtest" diff --git a/UltiSnips/php.snippets b/UltiSnips/php.snippets index 40461d2..3245568 100644 --- a/UltiSnips/php.snippets +++ b/UltiSnips/php.snippets @@ -11,8 +11,8 @@ endsnippet snippet do "do" do { - ${2:// code... } -} while (${1:/* condition */});" + ${2} +} while (${1});" endsnippet snippet doc_f "doc_f" @@ -37,21 +37,21 @@ interface ${1:someClass} } // END interface $1" endsnippet -snippet else "else" +snippet el "else" else { - ${1:// code...} + ${1} } endsnippet snippet for "for" for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) { - ${4:// code...} + ${4} } endsnippet snippet foreachk "foreachk" foreach ($${1:variable} as $${2:key} => $${3:value}){ - ${4:// code...} + ${4} } endsnippet @@ -60,8 +60,8 @@ $_GET['${1}']${2} endsnippet snippet if "if" -if (${1:/* condition */}) { - ${2:// code...} +if (${1}) { + ${2} } endsnippet @@ -210,9 +210,9 @@ endsnippet snippet ife "if else" if (${1:/* condition */}) { - ${2:// code...} + ${2} } else { - ${3:// code...} + ${3} } $0 endsnippet @@ -227,7 +227,7 @@ class $1 { public function ${3:__construct}(${4:$options}) { - ${4:// code} + ${4} } } $0 diff --git a/UltiSnips/tcl.snippets b/UltiSnips/tcl.snippets index 2cb1f34..c5ae37b 100644 --- a/UltiSnips/tcl.snippets +++ b/UltiSnips/tcl.snippets @@ -16,14 +16,14 @@ foreach ${1:var} ${2:\$list} { endsnippet snippet if "if... (if)" b -if {${1:condition}} { +if {${1}} { ${2} } endsnippet snippet proc "proc... (proc)" b -proc ${1:name} {${2:args}} \ +proc ${1} {${2}} \ { ${3} } @@ -41,7 +41,7 @@ switch ${1:-exact} -- ${2:\$var} { endsnippet snippet while "while... (while)" b -while {${1:condition}} { +while {${1}} { ${2} } diff --git a/UltiSnips/vim.snippets b/UltiSnips/vim.snippets index f4c37f0..5655c4b 100644 --- a/UltiSnips/vim.snippets +++ b/UltiSnips/vim.snippets @@ -25,30 +25,30 @@ endsnippet snippet f fun ${1:function_name}(${2}) - ${3:" code} + ${3} endf endsnippet snippet for -for ${1:needle} in ${2:haystack} - ${3:" code} +for ${1} in ${2} + ${3} endfor endsnippet snippet wh -while ${1:condition} - ${2:" code} +while ${1} + ${2} endw endsnippet snippet if -if ${1:condition} - ${2:" code} +if ${1} + ${2} endif endsnippet snippet ife -if ${1:condition} +if ${1} ${2} else ${3} diff --git a/snippets/autoit.snippets b/snippets/autoit.snippets index 690018c..c266e33 100644 --- a/snippets/autoit.snippets +++ b/snippets/autoit.snippets @@ -5,17 +5,17 @@ snippet if snippet el Else ${1} -snippet elif +snippet eif ElseIf ${1:condition} Then ${2:; True code} # If/Else block -snippet ifel +snippet ife If ${1:condition} Then ${2:; True code} Else ${3:; Else code} EndIf -# If/ElseIf/Else block +# If/ElseIf/Else block - because there is eif this is not really neccessary snippet ifelif If ${1:condition 1} Then ${2:; True code} diff --git a/snippets/coffee.snippets b/snippets/coffee.snippets index 11c82e7..21c2cc3 100644 --- a/snippets/coffee.snippets +++ b/snippets/coffee.snippets @@ -63,7 +63,7 @@ snippet ife else ${3:# body...} # Else if -snippet elif +snippet eif else if ${1:condition} ${2:# body...} # Ternary If diff --git a/snippets/falcon.snippets b/snippets/falcon.snippets index 3fe4cac..78257b6 100644 --- a/snippets/falcon.snippets +++ b/snippets/falcon.snippets @@ -32,7 +32,7 @@ snippet ife end # If else if -snippet elif +snippet eif elif ${1:condition} ${2} diff --git a/snippets/htmldjango.snippets b/snippets/htmldjango.snippets index 09cf98e..4ff5d33 100644 --- a/snippets/htmldjango.snippets +++ b/snippets/htmldjango.snippets @@ -47,10 +47,10 @@ snippet if {% if ${1} %} ${2} {% endif %} -snippet else +snippet el {% else %} ${1} -snippet elif +snippet eif {% elif ${1} %} ${2} snippet ifchanged diff --git a/snippets/htmltornado.snippets b/snippets/htmltornado.snippets index 9685b1f..e80499c 100644 --- a/snippets/htmltornado.snippets +++ b/snippets/htmltornado.snippets @@ -27,9 +27,9 @@ snippet if {% if ${1:condition} %} ${2} {% end %} -snippet elif +snippet eif {% elif ${1:condition} %} -snippet else +snippet el {% else %} snippet import {% import ${1:module} %} diff --git a/snippets/java.snippets b/snippets/java.snippets index c34010c..4dc6ff0 100644 --- a/snippets/java.snippets +++ b/snippets/java.snippets @@ -72,7 +72,7 @@ snippet def ${2} snippet el else -snippet elif +snippet eif else if (${1}) ${2} snippet if if (${1}) ${2} diff --git a/snippets/mako.snippets b/snippets/mako.snippets index 2a0aef9..0f64187 100644 --- a/snippets/mako.snippets +++ b/snippets/mako.snippets @@ -22,7 +22,7 @@ snippet if if % if ${1:condition}: ${2:} % endif -snippet if if/else +snippet ife if/else % if ${1:condition}: ${2:} % else: diff --git a/snippets/perl.snippets b/snippets/perl.snippets index ef83e0f..cd3f459 100644 --- a/snippets/perl.snippets +++ b/snippets/perl.snippets @@ -8,31 +8,35 @@ snippet . # Function snippet sub sub ${1:function_name} { - ${2:#body ...} + ${2} } # Conditional snippet if if (${1}) { - ${2:# body...} + ${2} } # Conditional if..else snippet ife if (${1}) { - ${2:# body...} + ${2} } else { - ${3:# else...} + ${3} } # Conditional if..elsif..else snippet ifee if (${1}) { - ${2:# body...} + ${2} } elsif (${3}) { ${4:# elsif...} } else { - ${5:# else...} + ${5} + } +snippet eif + elsif (${1}) { + ${2} } # Conditional One-line snippet xif @@ -40,7 +44,7 @@ snippet xif # Unless conditional snippet unless unless (${1}) { - ${2:# body...} + ${2} } # Unless conditional One-line snippet xunless @@ -57,7 +61,7 @@ snippet eval # While Loop snippet wh while (${1}) { - ${2:# body...} + ${2} } # While Loop One-line snippet xwh @@ -65,7 +69,7 @@ snippet xwh # C-style For Loop snippet cfor for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) { - ${4:# body...} + ${4} } # For loop one-line snippet xfor @@ -73,7 +77,7 @@ snippet xfor # Foreach Loop snippet for foreach my $${1:x} (@${2:array}) { - ${3:# body...} + ${3} } # Foreach Loop One-line snippet fore @@ -127,7 +131,7 @@ snippet switch # Anonymous subroutine snippet asub sub { - ${1:# body } + ${1} } @@ -135,7 +139,7 @@ snippet asub # Begin block snippet begin BEGIN { - ${1:# begin body} + ${1} } # call package function with some parameter @@ -174,7 +178,7 @@ snippet given # switch-like case snippet when when (${1:case}) { - ${2:# body} + ${2} } # hash slice @@ -237,7 +241,7 @@ snippet subpod =cut sub ${1:subroutine_name} { - ${2:# body...} + ${2} } # Subroutine signature snippet parg @@ -318,7 +322,7 @@ snippet trunner snippet tsub sub t${1:number}_${2:test_case} :Test(${3:num_of_tests}) { my $self = shift; - ${4:# body} + ${4} } @@ -333,7 +337,7 @@ snippet trsub snippet tprep sub prep${1:number}_${2:test_case} :Test(startup) { my $self = shift; - ${4:# body} + ${4} } # cause failures to print stack trace diff --git a/snippets/php.snippets b/snippets/php.snippets index 97ec3e3..8b071fc 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -278,11 +278,11 @@ snippet ifeil ${3:} ${4} -snippet else +snippet el else { ${1} } -snippet elseif +snippet eif elseif (${1:/* condition */}) { ${2} } diff --git a/snippets/puppet.snippets b/snippets/puppet.snippets index 29fe6b3..b8dbe50 100644 --- a/snippets/puppet.snippets +++ b/snippets/puppet.snippets @@ -26,7 +26,7 @@ snippet if if $${1:variable} { ${2} } -snippet else +snippet el else { ${1} } diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index b9fbf21..9813c8e 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -68,7 +68,7 @@ snippet ife else ${3} end -snippet elsif +snippet eif elsif ${1:condition} ${2} snippet unless diff --git a/snippets/scala.snippets b/snippets/scala.snippets index 9a71ec2..e3999f8 100644 --- a/snippets/scala.snippets +++ b/snippets/scala.snippets @@ -15,7 +15,7 @@ snippet ifn ${2} } #if-else -snippet ifel +snippet ife if(${1:obj}) { ${2} } else { @@ -28,6 +28,10 @@ snippet ifelif } else if(${3:obj}) { ${4} } +snippet eif + else if(${3:obj}) { + ${4} + } #while loop snippet while while (${1:obj}) { diff --git a/snippets/tcl.snippets b/snippets/tcl.snippets index 4d456de..8c0674e 100644 --- a/snippets/tcl.snippets +++ b/snippets/tcl.snippets @@ -5,7 +5,7 @@ snippet #! # Process snippet pro proc ${1:function_name} {${2:args}} { - ${3:#body ...} + ${3} } #xif snippet xif @@ -13,19 +13,23 @@ snippet xif # Conditional snippet if if {${1}} { - ${2:# body...} + ${2} } # Conditional if..else snippet ife if {${1}} { - ${2:# body...} + ${2} } else { ${3:# else...} } +snippet eif + elseif {${1}} { + ${2} + } # Conditional if..elsif..else snippet ifee if {${1}} { - ${2:# body...} + ${2} } elseif {${3}} { ${4:# elsif...} } else { @@ -42,17 +46,17 @@ snippet catch # While Loop snippet wh while {${1}} { - ${2:# body...} + ${2} } # For Loop snippet for for {set ${2:var} 0} {$$2 < ${1:count}} {${3:incr} $2} { - ${4:# body...} + ${4} } # Foreach Loop snippet fore foreach ${1:x} {${2:#list}} { - ${3:# body...} + ${3} } # after ms script... snippet af diff --git a/snippets/vim.snippets b/snippets/vim.snippets index 728c402..98cb51e 100644 --- a/snippets/vim.snippets +++ b/snippets/vim.snippets @@ -19,19 +19,25 @@ snippet t ${3} endtry snippet for - for ${1:needle} in ${2:haystack} + for ${1} in ${2} ${3} endfor +snippet forkv + for [a,b] in items({2}) + ${3} + unlet a b + endfor + snippet wh - while ${1:condition} + while ${1} ${2} endw snippet if - if ${1:condition} + if ${1} ${2} endif snippet ife - if ${1:condition} + if ${1} ${2} else ${3} diff --git a/snippets/zsh.snippets b/snippets/zsh.snippets index 367a01c..b3fdb8c 100644 --- a/snippets/zsh.snippets +++ b/snippets/zsh.snippets @@ -12,7 +12,7 @@ snippet ife else ${3:# statements} fi -snippet elif +snippet eif elif ${1:condition} ; then ${2:# statements} snippet for