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.
This commit is contained in:
Marc Weber 2013-06-23 02:30:26 +02:00
parent eaa01e7254
commit 344ac6ea2c
27 changed files with 177 additions and 120 deletions

View File

@ -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 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. 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 Related repositories
==================== ====================
We also encourage people to maintain sets of snippets for particular use cases We also encourage people to maintain sets of snippets for particular use cases

View File

@ -22,7 +22,7 @@ else
${3:# body...} ${3:# body...}
endsnippet endsnippet
snippet elif "Else if" b snippet eif "Else if" b
else if ${1:condition} else if ${1:condition}
${0:# body...} ${0:# body...}
endsnippet endsnippet

View File

@ -126,7 +126,7 @@ else
} }
endsnippet endsnippet
snippet elif "else if (elif)" b snippet eif "else if (elif)" b
else if(${1:/*condition*/}) else if(${1:/*condition*/})
{ {
${VISUAL}${0:/*code*/} ${VISUAL}${0:/*code*/}

View File

@ -76,7 +76,7 @@ snippet if
{% endif %} {% endif %}
endsnippet endsnippet
snippet else snippet el
{% else %} {% else %}
${1} ${1}
endsnippet endsnippet

View File

@ -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)` `!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 endsnippet
snippet else "else (ERB)" snippet el "else (ERB)"
<% else %> <% else %>
endsnippet endsnippet

View File

@ -1,13 +1,13 @@
snippet if "if ... then ... else ..." snippet ife "if ... then ... else ..."
if ${1:condition} if ${1:condition}
then ${2:expression} then ${2:expression}
else ${3:expression} else ${3:expression}
endsnippet endsnippet
snippet case "case ... of ..." snippet case "case ... of ..."
case ${1:expression} of case ${1} of
${2:pattern} -> ${3:expression} ${2} -> ${3}
${4:pattern} -> ${5:expression} ${4} -> ${5}
endsnippet endsnippet
snippet :: "Type signature" snippet :: "Type signature"

View File

@ -59,7 +59,7 @@ default:
$0 $0
endsnippet endsnippet
snippet elif "else if" b snippet eif "else if" b
else if ($1)`!p nl(snip)`{ else if ($1)`!p nl(snip)`{
$0 $0
} }

View File

@ -50,12 +50,19 @@ function ${1:function_name} (${2:argument}) {
} }
endsnippet endsnippet
# for one line if .. else you usually use a ? b : c
snippet ife "if ___ else" snippet ife "if ___ else"
if (${1:true}) {$0} else{}; if (${1}) {
{$2}
} else {
{$3}
};
endsnippet endsnippet
snippet if "if" snippet if "if"
if (${1:true}) {$0}; if (${1}) {
{$2}
};
endsnippet endsnippet
snippet timeout "setTimeout function" snippet timeout "setTimeout function"

View File

@ -4,17 +4,17 @@ endsnippet
snippet open "open" snippet open "open"
let open ${1:module} in let open ${1:module} in
${2:e} ${2}
endsnippet endsnippet
snippet try "try" snippet try "try"
try ${1:e} try ${1}
with ${2:Not_found} -> ${3:()} with ${2:Not_found} -> ${3:()}
endsnippet endsnippet
snippet ref "ref" snippet ref "ref"
let ${1:name} = ref ${2:val} in let ${1} = ref ${2} in
${3:e} ${3}
endsnippet endsnippet
snippet matchl "pattern match on a list" snippet matchl "pattern match on a list"
@ -24,88 +24,83 @@ match ${1:list} with
endsnippet endsnippet
snippet matcho "pattern match on an option type" snippet matcho "pattern match on an option type"
match ${1:x} with match ${1} with
| Some(${2:y}) -> ${3:()} | Some(${2}) -> ${3:()}
| None -> ${4:()} | None -> ${4:()}
endsnippet endsnippet
snippet fun "anonymous function" snippet fun "anonymous function"
(fun ${1:x} -> ${2:x}) (fun ${1} -> ${2})
endsnippet endsnippet
snippet cc "commment" snippet cc "commment"
(* ${1:comment} *) (* ${1} *)
endsnippet endsnippet
snippet let "let .. in binding" snippet let "let .. in binding"
let ${1:x} = ${2:v} in let ${1} = ${2} in
${3:e} ${3}
endsnippet endsnippet
snippet lr "let rec" snippet lr "let rec"
let rec ${1:f} = let rec ${1} =
${2:expr} ${2}
endsnippet endsnippet
snippet if "if" snippet ife "if"
if ${1:(* condition *)} then if ${1} then
${2:(* A *)} ${2}
else else
${3:(* B *)} ${3}
endsnippet endsnippet
snippet If "If" snippet if "If"
if ${1:(* condition *)} then if ${1} then
${2:(* A *)} ${2}
endsnippet endsnippet
snippet while "while" snippet while "while"
while ${1:(* condition *)} do while ${1} do
${2:(* A *)} ${2}
done done
endsnippet endsnippet
snippet for "for" snippet for "for"
for ${1:i} = ${2:1} to ${3:10} do for ${1:i} = ${2:1} to ${3:10} do
${4:(* BODY *)} ${4}
done done
endsnippet endsnippet
snippet match "match" snippet match "match"
match ${1:(* e1 *)} with match ${1} with
| ${2:p} -> ${3:e2} | ${2} -> ${3}
endsnippet
snippet Match "match"
match ${1:(* e1 *)} with
| ${2:p} -> ${3:e2}
endsnippet endsnippet
snippet class "class" snippet class "class"
class ${1:name} = object class ${1:name} = object
${2:methods} ${2}
end end
endsnippet endsnippet
snippet obj "obj" snippet obj "obj"
object object
${2:methods} ${2}
end end
endsnippet endsnippet
snippet Obj "object" snippet Obj "object"
object (self) object (self)
${2:methods} ${2}
end end
endsnippet endsnippet
snippet {{ "object functional update" snippet {{ "object functional update"
{< ${1:x} = ${2:y} >} {< ${1} = ${2} >}
endsnippet endsnippet
snippet beg "beg" snippet beg "beg"
begin begin
${1:block} ${1}${VISUAL}
end end
endsnippet endsnippet
@ -115,19 +110,19 @@ endsnippet
snippet mod "module - no signature" snippet mod "module - no signature"
module ${1:(* Name *)} = struct module ${1:(* Name *)} = struct
${2:(* BODY *)} ${2}
end end
endsnippet endsnippet
snippet Mod "module with signature" snippet Mod "module with signature"
module ${1:(* Name *)} : ${2:(* SIG *)} = struct module ${1:(* Name *)} : ${2:(* SIG *)} = struct
${3:(* BODY *)} ${3}
end end
endsnippet endsnippet
snippet sig "anonymous signature" snippet sig "anonymous signature"
sig sig
${2:(* BODY *)} ${2}
end end
endsnippet endsnippet
@ -137,32 +132,32 @@ endsnippet
snippet func "define functor - no signature" snippet func "define functor - no signature"
module ${1:M} (${2:Arg} : ${3:ARG}) = struct module ${1:M} (${2:Arg} : ${3:ARG}) = struct
${4:(* BODY *)} ${4}
end end
endsnippet endsnippet
snippet Func "define functor - with signature" snippet Func "define functor - with signature"
module ${1:M} (${2:Arg} : ${3:ARG}) : ${4:SIG} = struct module ${1:M} (${2:Arg} : ${3:ARG}) : ${4:SIG} = struct
${5:(* BODY *)} ${5}
end end
endsnippet endsnippet
snippet mot "Declare module signature" snippet mot "Declare module signature"
module type ${1:(* Name *)} = sig module type ${1:(* Name *)} = sig
${2:(* BODY *)} ${2}
end end
endsnippet endsnippet
snippet module "Module with anonymous signature" snippet module "Module with anonymous signature"
module ${1:(* Name *)} : sig module ${1:(* Name *)} : sig
${2:(* SIGNATURE *)} ${2}
end = struct end = struct
${3:(* BODY *)} ${3}
end end
endsnippet endsnippet
snippet oo "odoc" snippet oo "odoc"
(** ${1:odoc} *) (** ${1} *)
endsnippet endsnippet
snippet qt "inline qtest" snippet qt "inline qtest"

View File

@ -11,8 +11,8 @@ endsnippet
snippet do "do" snippet do "do"
do { do {
${2:// code... } ${2}
} while (${1:/* condition */});" } while (${1});"
endsnippet endsnippet
snippet doc_f "doc_f" snippet doc_f "doc_f"
@ -37,21 +37,21 @@ interface ${1:someClass}
} // END interface $1" } // END interface $1"
endsnippet endsnippet
snippet else "else" snippet el "else"
else { else {
${1:// code...} ${1}
} }
endsnippet endsnippet
snippet for "for" snippet for "for"
for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) { for ($${2:i} = 0; $$2 < ${1:count}; $$2${3:++}) {
${4:// code...} ${4}
} }
endsnippet endsnippet
snippet foreachk "foreachk" snippet foreachk "foreachk"
foreach ($${1:variable} as $${2:key} => $${3:value}){ foreach ($${1:variable} as $${2:key} => $${3:value}){
${4:// code...} ${4}
} }
endsnippet endsnippet
@ -60,8 +60,8 @@ $_GET['${1}']${2}
endsnippet endsnippet
snippet if "if" snippet if "if"
if (${1:/* condition */}) { if (${1}) {
${2:// code...} ${2}
} }
endsnippet endsnippet
@ -210,9 +210,9 @@ endsnippet
snippet ife "if else" snippet ife "if else"
if (${1:/* condition */}) { if (${1:/* condition */}) {
${2:// code...} ${2}
} else { } else {
${3:// code...} ${3}
} }
$0 $0
endsnippet endsnippet
@ -227,7 +227,7 @@ class $1
{ {
public function ${3:__construct}(${4:$options}) public function ${3:__construct}(${4:$options})
{ {
${4:// code} ${4}
} }
} }
$0 $0

View File

@ -16,14 +16,14 @@ foreach ${1:var} ${2:\$list} {
endsnippet endsnippet
snippet if "if... (if)" b snippet if "if... (if)" b
if {${1:condition}} { if {${1}} {
${2} ${2}
} }
endsnippet endsnippet
snippet proc "proc... (proc)" b snippet proc "proc... (proc)" b
proc ${1:name} {${2:args}} \ proc ${1} {${2}} \
{ {
${3} ${3}
} }
@ -41,7 +41,7 @@ switch ${1:-exact} -- ${2:\$var} {
endsnippet endsnippet
snippet while "while... (while)" b snippet while "while... (while)" b
while {${1:condition}} { while {${1}} {
${2} ${2}
} }

View File

@ -25,30 +25,30 @@ endsnippet
snippet f snippet f
fun ${1:function_name}(${2}) fun ${1:function_name}(${2})
${3:" code} ${3}
endf endf
endsnippet endsnippet
snippet for snippet for
for ${1:needle} in ${2:haystack} for ${1} in ${2}
${3:" code} ${3}
endfor endfor
endsnippet endsnippet
snippet wh snippet wh
while ${1:condition} while ${1}
${2:" code} ${2}
endw endw
endsnippet endsnippet
snippet if snippet if
if ${1:condition} if ${1}
${2:" code} ${2}
endif endif
endsnippet endsnippet
snippet ife snippet ife
if ${1:condition} if ${1}
${2} ${2}
else else
${3} ${3}

View File

@ -5,17 +5,17 @@ snippet if
snippet el snippet el
Else Else
${1} ${1}
snippet elif snippet eif
ElseIf ${1:condition} Then ElseIf ${1:condition} Then
${2:; True code} ${2:; True code}
# If/Else block # If/Else block
snippet ifel snippet ife
If ${1:condition} Then If ${1:condition} Then
${2:; True code} ${2:; True code}
Else Else
${3:; Else code} ${3:; Else code}
EndIf EndIf
# If/ElseIf/Else block # If/ElseIf/Else block - because there is eif this is not really neccessary
snippet ifelif snippet ifelif
If ${1:condition 1} Then If ${1:condition 1} Then
${2:; True code} ${2:; True code}

View File

@ -63,7 +63,7 @@ snippet ife
else else
${3:# body...} ${3:# body...}
# Else if # Else if
snippet elif snippet eif
else if ${1:condition} else if ${1:condition}
${2:# body...} ${2:# body...}
# Ternary If # Ternary If

View File

@ -32,7 +32,7 @@ snippet ife
end end
# If else if # If else if
snippet elif snippet eif
elif ${1:condition} elif ${1:condition}
${2} ${2}

View File

@ -47,10 +47,10 @@ snippet if
{% if ${1} %} {% if ${1} %}
${2} ${2}
{% endif %} {% endif %}
snippet else snippet el
{% else %} {% else %}
${1} ${1}
snippet elif snippet eif
{% elif ${1} %} {% elif ${1} %}
${2} ${2}
snippet ifchanged snippet ifchanged

View File

@ -27,9 +27,9 @@ snippet if
{% if ${1:condition} %} {% if ${1:condition} %}
${2} ${2}
{% end %} {% end %}
snippet elif snippet eif
{% elif ${1:condition} %} {% elif ${1:condition} %}
snippet else snippet el
{% else %} {% else %}
snippet import snippet import
{% import ${1:module} %} {% import ${1:module} %}

View File

@ -72,7 +72,7 @@ snippet def
${2} ${2}
snippet el snippet el
else else
snippet elif snippet eif
else if (${1}) ${2} else if (${1}) ${2}
snippet if snippet if
if (${1}) ${2} if (${1}) ${2}

View File

@ -22,7 +22,7 @@ snippet if if
% if ${1:condition}: % if ${1:condition}:
${2:} ${2:}
% endif % endif
snippet if if/else snippet ife if/else
% if ${1:condition}: % if ${1:condition}:
${2:} ${2:}
% else: % else:

View File

@ -8,31 +8,35 @@ snippet .
# Function # Function
snippet sub snippet sub
sub ${1:function_name} { sub ${1:function_name} {
${2:#body ...} ${2}
} }
# Conditional # Conditional
snippet if snippet if
if (${1}) { if (${1}) {
${2:# body...} ${2}
} }
# Conditional if..else # Conditional if..else
snippet ife snippet ife
if (${1}) { if (${1}) {
${2:# body...} ${2}
} }
else { else {
${3:# else...} ${3}
} }
# Conditional if..elsif..else # Conditional if..elsif..else
snippet ifee snippet ifee
if (${1}) { if (${1}) {
${2:# body...} ${2}
} }
elsif (${3}) { elsif (${3}) {
${4:# elsif...} ${4:# elsif...}
} }
else { else {
${5:# else...} ${5}
}
snippet eif
elsif (${1}) {
${2}
} }
# Conditional One-line # Conditional One-line
snippet xif snippet xif
@ -40,7 +44,7 @@ snippet xif
# Unless conditional # Unless conditional
snippet unless snippet unless
unless (${1}) { unless (${1}) {
${2:# body...} ${2}
} }
# Unless conditional One-line # Unless conditional One-line
snippet xunless snippet xunless
@ -57,7 +61,7 @@ snippet eval
# While Loop # While Loop
snippet wh snippet wh
while (${1}) { while (${1}) {
${2:# body...} ${2}
} }
# While Loop One-line # While Loop One-line
snippet xwh snippet xwh
@ -65,7 +69,7 @@ snippet xwh
# C-style For Loop # C-style For Loop
snippet cfor snippet cfor
for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) { for (my $${2:var} = 0; $$2 < ${1:count}; $$2${3:++}) {
${4:# body...} ${4}
} }
# For loop one-line # For loop one-line
snippet xfor snippet xfor
@ -73,7 +77,7 @@ snippet xfor
# Foreach Loop # Foreach Loop
snippet for snippet for
foreach my $${1:x} (@${2:array}) { foreach my $${1:x} (@${2:array}) {
${3:# body...} ${3}
} }
# Foreach Loop One-line # Foreach Loop One-line
snippet fore snippet fore
@ -127,7 +131,7 @@ snippet switch
# Anonymous subroutine # Anonymous subroutine
snippet asub snippet asub
sub { sub {
${1:# body } ${1}
} }
@ -135,7 +139,7 @@ snippet asub
# Begin block # Begin block
snippet begin snippet begin
BEGIN { BEGIN {
${1:# begin body} ${1}
} }
# call package function with some parameter # call package function with some parameter
@ -174,7 +178,7 @@ snippet given
# switch-like case # switch-like case
snippet when snippet when
when (${1:case}) { when (${1:case}) {
${2:# body} ${2}
} }
# hash slice # hash slice
@ -237,7 +241,7 @@ snippet subpod
=cut =cut
sub ${1:subroutine_name} { sub ${1:subroutine_name} {
${2:# body...} ${2}
} }
# Subroutine signature # Subroutine signature
snippet parg snippet parg
@ -318,7 +322,7 @@ snippet trunner
snippet tsub snippet tsub
sub t${1:number}_${2:test_case} :Test(${3:num_of_tests}) { sub t${1:number}_${2:test_case} :Test(${3:num_of_tests}) {
my $self = shift; my $self = shift;
${4:# body} ${4}
} }
@ -333,7 +337,7 @@ snippet trsub
snippet tprep snippet tprep
sub prep${1:number}_${2:test_case} :Test(startup) { sub prep${1:number}_${2:test_case} :Test(startup) {
my $self = shift; my $self = shift;
${4:# body} ${4}
} }
# cause failures to print stack trace # cause failures to print stack trace

View File

@ -278,11 +278,11 @@ snippet ifeil
${3:<!-- html... -->} ${3:<!-- html... -->}
<?php endif; ?> <?php endif; ?>
${4} ${4}
snippet else snippet el
else { else {
${1} ${1}
} }
snippet elseif snippet eif
elseif (${1:/* condition */}) { elseif (${1:/* condition */}) {
${2} ${2}
} }

View File

@ -26,7 +26,7 @@ snippet if
if $${1:variable} { if $${1:variable} {
${2} ${2}
} }
snippet else snippet el
else { else {
${1} ${1}
} }

View File

@ -68,7 +68,7 @@ snippet ife
else else
${3} ${3}
end end
snippet elsif snippet eif
elsif ${1:condition} elsif ${1:condition}
${2} ${2}
snippet unless snippet unless

View File

@ -15,7 +15,7 @@ snippet ifn
${2} ${2}
} }
#if-else #if-else
snippet ifel snippet ife
if(${1:obj}) { if(${1:obj}) {
${2} ${2}
} else { } else {
@ -28,6 +28,10 @@ snippet ifelif
} else if(${3:obj}) { } else if(${3:obj}) {
${4} ${4}
} }
snippet eif
else if(${3:obj}) {
${4}
}
#while loop #while loop
snippet while snippet while
while (${1:obj}) { while (${1:obj}) {

View File

@ -5,7 +5,7 @@ snippet #!
# Process # Process
snippet pro snippet pro
proc ${1:function_name} {${2:args}} { proc ${1:function_name} {${2:args}} {
${3:#body ...} ${3}
} }
#xif #xif
snippet xif snippet xif
@ -13,19 +13,23 @@ snippet xif
# Conditional # Conditional
snippet if snippet if
if {${1}} { if {${1}} {
${2:# body...} ${2}
} }
# Conditional if..else # Conditional if..else
snippet ife snippet ife
if {${1}} { if {${1}} {
${2:# body...} ${2}
} else { } else {
${3:# else...} ${3:# else...}
} }
snippet eif
elseif {${1}} {
${2}
}
# Conditional if..elsif..else # Conditional if..elsif..else
snippet ifee snippet ifee
if {${1}} { if {${1}} {
${2:# body...} ${2}
} elseif {${3}} { } elseif {${3}} {
${4:# elsif...} ${4:# elsif...}
} else { } else {
@ -42,17 +46,17 @@ snippet catch
# While Loop # While Loop
snippet wh snippet wh
while {${1}} { while {${1}} {
${2:# body...} ${2}
} }
# For Loop # For Loop
snippet for snippet for
for {set ${2:var} 0} {$$2 < ${1:count}} {${3:incr} $2} { for {set ${2:var} 0} {$$2 < ${1:count}} {${3:incr} $2} {
${4:# body...} ${4}
} }
# Foreach Loop # Foreach Loop
snippet fore snippet fore
foreach ${1:x} {${2:#list}} { foreach ${1:x} {${2:#list}} {
${3:# body...} ${3}
} }
# after ms script... # after ms script...
snippet af snippet af

View File

@ -19,19 +19,25 @@ snippet t
${3} ${3}
endtry endtry
snippet for snippet for
for ${1:needle} in ${2:haystack} for ${1} in ${2}
${3} ${3}
endfor endfor
snippet forkv
for [a,b] in items({2})
${3}
unlet a b
endfor
snippet wh snippet wh
while ${1:condition} while ${1}
${2} ${2}
endw endw
snippet if snippet if
if ${1:condition} if ${1}
${2} ${2}
endif endif
snippet ife snippet ife
if ${1:condition} if ${1}
${2} ${2}
else else
${3} ${3}

View File

@ -12,7 +12,7 @@ snippet ife
else else
${3:# statements} ${3:# statements}
fi fi
snippet elif snippet eif
elif ${1:condition} ; then elif ${1:condition} ; then
${2:# statements} ${2:# statements}
snippet for snippet for