Snippet library¶
This document contains snippet examples for most of snippets from standard library.
Core¶
There are few snippets that are used to create the structure of snippets. They can also be used to add parameters that can be used inside the snippet.
block:
block>line1&line2
line1
line2
wblock (wide block):
wblock>line1&line2
line1
line2
Note that block
is the implicit parent of all snippets. Next snippet sill have the same result.
line1&line2
line1
line2
C++¶
Commands¶
call (function call):
call@foo$param1>param2
foo(param1, param2);
call2 (function call in multiple lines):
call2@foo$param1>param2
foo(
param1,
param2
);
stdinc:
stdinc$stdio.h
#include <stdio.h>
inc:
inc$homotopy.h
#include "homotopy.h"
Flow control¶
for:
for#int$i%0%n
for(int i=0; i<n; i++){
}
forr:
forr#int$i%n%0
for(int i=n; i>=0; i--){
}
forin:
forin#int$i%array
for(int i: array){
}
if:
if$true>printf("Always");
if(true){
printf("Always");
}
else:
if$i==2>return 4;<else>return 3;
if(i==2){
return 4;
}
else {
return 3;
}
while:
while$true>printf("Forever and always");
while(true){
printf("Forever and always");
}
switch:
switch$i>case$1>printf("one");<case$2>printf("two");
switch(i){
case 1:
printf("one");
break;
case 2:
printf("two");
break;
}
switch$i>case$1$2>printf("one or two");
switch(i){
case 1:
case 2:
printf("one or two");
break;
}
Objects¶
struct:
struct!pair>int first, second;
struct pair {
int first, second;
};
class:
class!A:B%public>private>int a;<public>int b;
class A: public B {
private:
int a;
public:
int b;
};
enum:
enum!Colors>red&green&blue
enum Colors {
red,
green,
blue
};
enum1 (enum in single line):
enum1!Colors>red&green&blue
enum Colors { red, green, blue };
Functions¶
func (function):
func#int@five>return 5;
int five(){
return 5;
}
func#int@plus#int$i#int$j>return i+j;
int plus(int i, int j){
return i+j;
}
func#int@plus$i$j#int>return i+j;
int plus(int i, int j){
return i+j;
}
Note that values i
and j
are specified first and type int after.
This makes both i
and j
ints without typing int twice.
method:
class!A>public>method#int@five>return 5;
class A {
public:
int five(){
return 5;
}
};
nimethod (not implemented method):
class!A>public>nimethod#int@five
class A {
public:
int five();
};
amethod (abstract method):
class!A>public>amethod#int@five
class A {
public:
int five() = 0;
};
dmethod (deleted method):
class!A>public>dmethod#int@five
class A {
public:
int five() = delete;
};
methodi1 (single method implementation):
methodi1!A#int@five>return 5;
int A::five(){
return 5;
}
mithodi (method implementation):
wblock!A>methodi#int@five>return 5;<methodi#int@six>return 6;
int A::five(){
return 5;
}
int A::six(){
return 6;
}
Note that wblock
is used here to bind class parameter that is used by both children snippets.
constr (constructor):
class!A>public>constr#int$i
class A {
public:
A(int i){
}
};
Templates¶
template:
class!A^T
template <class T>
class A {
};
func@nothing#void^T
template <class T>
void nothing(){
}
class!A>public>method#void@nothing^T
class A {
public:
template <class T>
void nothing(){
}
};
Design Patterns¶
singleton:
class!A>[[singleton]]
class A {
public:
A& getInstance(){
static A instance;
return instance;
}
private:
A(){}
A(A const& origin);
void operator=(A const& origin);
};
composite (class and method):
class!Composite:Component%public>[[compositeclass]]&public>method#void@traverse>[[compositemethod]]
class Composite: public Component {
public:
void add(Component *item){
children.puch_back(item);
}
private:
std::vector<Component*> children;
public:
void traverse(){
for(int i=0; i<children.size(); i++){
children[i]->traverse();
}
}
};
C¶
Commands¶
call (function call):
call@foo$param1>param2
foo(param1, param2);
call2 (function call in multiple lines):
call2@foo$param1>param2
foo(
param1,
param2
);
stdinc:
stdinc$stdio.h
#include <stdio.h>
inc:
inc$homotopy.h
#include "homotopy.h"
Flow control¶
for:
for#int$i%0%n
for(int i=0; i<n; i++){
}
forr:
forr#int$i%n%0
for(int i=n; i>=0; i--){
}
if:
if$true>printf("Always");
if(true){
printf("Always");
}
else:
if$i==2>return 4;<else>return 3;
if(i==2){
return 4;
}
else {
return 3;
}
while:
while$true>printf("Forever and always");
while(true){
printf("Forever and always");
}
switch:
switch$i>case$1>printf("one");<case$2>printf("two");
switch(i){
case 1:
printf("one");
break;
case 2:
printf("two");
break;
}
switch$i>case$1$2>printf("one or two");
switch(i){
case 1:
case 2:
printf("one or two");
break;
}
Objects¶
struct:
struct!pair>int first, second;
struct pair {
int first, second;
};
tdstruct (typedef struct):
tdstruct!pair>int first, second;
typedef struct{
int first, second;
} pair;
enum:
enum!Colors>red&green&blue
enum Colors {
red,
green,
blue
};
enum1 (enum in single line):
enum1!Colors>red&green&blue
enum Colors { red, green, blue };
Java¶
Commands¶
call (function call):
call@foo$param1>param2
foo(param1, param2);
call2 (function call in multiple lines):
call2@foo$param1>param2
foo(
param1,
param2
);
Flow control¶
for:
for#int$i%0%n
for(int i=0; i<n; i++){
}
forr:
forr#int$i%n%0
for(int i=n; i>=0; i--){
}
forin:
forin#int$i%array
for(int i: array){
}
if:
if$true>printf("Always");
if(true){
printf("Always");
}
else:
if$i==2>return 4;<else>return 3;
if(i==2){
return 4;
}
else {
return 3;
}
while:
while$true>printf("Forever and always");
while(true){
printf("Forever and always");
}
switch:
switch$i>case$1>printf("one");<case$2>printf("two");
switch(i){
case 1:
printf("one");
break;
case 2:
printf("two");
break;
}
switch$i>case$1$2>printf("one or two");
switch(i){
case 1:
case 2:
printf("one or two");
break;
}
Objects¶
class:
class!A:B~C
class A extends B implements C {
}
method:
class!A:B>method#int@five
class A extends B {
public int five(){
}
}
pmethod (private method):
class!A:B>pmethod#int@five
class A extends B {
private int five(){
}
}
promethod (protected method):
class!A:B>method#int@five
class A extends B {
protected int five(){
}
}
amethod (abstract method):
class!A:B>amethod#int@five
class A extends B {
public int abstract five();
}
amethod (abstract method):
class!A:B>amethod#int@five
class A extends B {
public abstract int five();
}
pamethod (private abstract method):
class!A:B>pamethod#int@five
class A extends B {
private abstract int five();
}
method1 (single line method):
class!A:B>method1#int@five>return 5;
class A extends B {
public int five(){ return 5; }
}
constr (constructor):
class!A:B>constr#int$i
class A extends B {
public A(int i){
}
}
constr1 (single line constructor):
class!A:B>constr1
class A extends B {
public A(){ }
}
pconstr (private constructor):
class!A:B>pconstr
class A extends B {
private A(){
}
}
enum:
enum!Colors>red&green&blue
enum Colors {
red,
green,
blue
}
enum1 (single line enum):
enum1!Colors>red&green&blue
enum Colors { red, green, blue }
Templates¶
class template:
class!A^T
class A<T> {
}
method template:
class!A>method#void@nothing^T
class A {
public void nothing<T>(){
}
}
Design Patterns¶
singleton:
class!A>[[singleton]]
class A {
private static A instance = null;
peconstr
public static A getInstance(){
if(instance == null){
instance = new A();
}
return instance;
}
}
composite (class and method):
class!Composite:Component>[[compositeclass]]&method#void@traverse>[[compositemethod]]
class Composite extends Component {
private List<Component> children = ArrayList<Component>();
public void add(Component item){
children.add(item);
}
public void traverse(){
for(int i=0; i<children.size(); i++){
children[i].traverse();
}
}
}
Python¶
Flow control¶
forin:
forin$i%collection>pass
for i in collection:
pass
for (same as forin but shorter):
for$i%collection>pass
for i in collection:
pass
if:
if$i==0>print("i is zero")
if i==0:
print("i is zero")
else:
if$i==0>print("i is zero")<else>print("i is not zero")
if i==0:
print("i is zero")
else:
print("i is not zero")
elif:
if$i==0>print("i is zero")<elif$i==1>print("i is one")<else>print("i is not zero nor one")
if i==0:
print("i is zero")
elif i==1:
print("i is one")
else:
print("i is not zero nor one")
while:
while$condition>doSomething()
while condition:
doSomething()
Objects¶
func:
func@foo$i>pass
def foo(i):
pass
class:
class!A:B>pass
class A(B):
pass
method:
class!A:B>method@foo$i>pass
class A(B):
def foo(self, i):
pass
smethod (static method):
class!A:B>smethod@foo$i>pass
class A(B):
@staticmethod
def foo(i):
pass
cmethod (class method):
class!A:B>cmethod@foo$i>pass
class A(B):
@classmethod
def foo(cls, i):
pass
constr (constructor):
class!A:B>constr$i>pass
class A(B):
def __init__(self, i):
pass
JavaScript¶
Commands¶
call (function call):
call@foo$param1>param2
foo(param1, param2);
call2 (function call in multiple lines):
call2@foo$param1>f>3
foo(
param1,
function (){ return 3; }
);
var:
var$x$3
var x = 3;
var$plus>a$i$j>i+j
var plus = (i, j) => i+j;
let:
let$x$3
let x = 3;
Flow control¶
for:
for#var$i%0%n
for(var i=0; i<n; i++){
}
forr:
forr#var$i%n%0
for(var i=n; i>=0; i--){
}
forin:
forin$i%array
for(let i of array){
}
forof:
forof$i%array
for(let i of array){
}
if:
if$true>console.log("Always");
if(true){
console.log("Always");
}
else:
if$i==2>return 4;<else>return 3;
if(i==2){
return 4;
}
else {
return 3;
}
while:
while$true>console.log("Forever and always");
while(true){
console.log("Forever and always");
}
switch:
switch$i>case$1>console.log("one");<case$2>console.log("two");
switch(i){
case 1:
console.log("one");
break;
case 2:
console.log("two");
break;
}
switch$i>case$1$2>console.log("one or two");
switch(i){
case 1:
case 2:
console.log("one or two");
break;
}
Object¶
dict (dictionary):
dict>key$item1$1&key$item2$2
{
item1: 1,
item2: 2
}
d (dictionary, short):
d>k$item1$1&k$item2$2
{
"item1": 1,
"item2": 2
}
d (dictionary, nested example):
d>k$item1>d>k$nested$1<<&k$item2$2
{
"item1": {
"nested": 1
},
"item2": 2
}
dict1 (dictionary, single line):
dict1>key$"item1"$1&k$item2$2
{"item1": 1, "item2": 2}
Note that key
is used to build arbitrary key and k
is used to build a string key.
array:
array>item1&item2
[
item1,
item2
]
array1 (array, single line):
array1>item1&item2
[item1, item2]
Functions¶
func (function):
func@plus$i$j>return i+j;
function plus(i, j){
return i+j;
}
func$i$j>return i+j;
function (i, j){
return i+j;
}
func1 (function, single line):
func1$i$j>return i+j;
function (i, j){ return i+j; }
f (function, single expression):
f$i$j>i+j
function (i, j){ return i+j; }
arrow (arrow function):
arrow$i$j>return i+j;
(i, j) => {
return i+j;
}
arrow1 (arrow function, single line):
arrow1$i$j>return i+j;
(i, j) => { return i+j; }
a (arrow function, single expression):
a$i$j>i+j
(i, j) => i+j