Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
66c2a0b026
@ -194,7 +194,7 @@ endsnippet
|
|||||||
|
|
||||||
snippet head "XHTML <head>"
|
snippet head "XHTML <head>"
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"`!p x(snip)`>
|
<meta charset="utf-8">
|
||||||
<title>${1:`!p snip.rv = snip.basename or "Page Title"`}</title>
|
<title>${1:`!p snip.rv = snip.basename or "Page Title"`}</title>
|
||||||
$0
|
$0
|
||||||
</head>
|
</head>
|
||||||
|
@ -25,8 +25,13 @@ def getArgs(group):
|
|||||||
return [i.split(" ") for i in word.findall(group) ]
|
return [i.split(" ") for i in word.findall(group) ]
|
||||||
|
|
||||||
def camel(word):
|
def camel(word):
|
||||||
|
if not word: return ''
|
||||||
return word[0].upper() + word[1:]
|
return word[0].upper() + word[1:]
|
||||||
|
|
||||||
|
def mixedCase(word):
|
||||||
|
if not word: return ''
|
||||||
|
return word[0].lower() + word[1:]
|
||||||
|
|
||||||
endglobal
|
endglobal
|
||||||
|
|
||||||
snippet sleep "try sleep catch" b
|
snippet sleep "try sleep catch" b
|
||||||
@ -173,13 +178,13 @@ default:
|
|||||||
$0
|
$0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet elif "else if" b
|
snippet elif "else if"
|
||||||
else if ($1)`!p nl(snip)`{
|
else if ($1)`!p nl(snip)`{
|
||||||
$0
|
$0
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet /el(se)?/ "else" br
|
snippet /el(se)?/ "else" r
|
||||||
else`!p nl(snip)`{
|
else`!p nl(snip)`{
|
||||||
$0
|
$0
|
||||||
}
|
}
|
||||||
@ -338,23 +343,23 @@ endsnippet
|
|||||||
|
|
||||||
snippet /get(ter)?/ "getter" br
|
snippet /get(ter)?/ "getter" br
|
||||||
public ${1:String} get${2:Name}() {
|
public ${1:String} get${2:Name}() {
|
||||||
return `!p snip.rv = t[2].lower()`;
|
return `!p snip.rv = mixedCase(t[2])`;
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet /set(ter)?/ "setter" br
|
snippet /set(ter)?/ "setter" br
|
||||||
public void set${1:Name}(${2:String} $1) {
|
public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) {
|
||||||
return this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`;
|
this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`;
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet /se?tge?t|ge?tse?t|gs/ "setter and getter" br
|
snippet /se?tge?t|ge?tse?t|gs/ "setter and getter" br
|
||||||
public void set${1:Name}(${2:String} `!p snip.rv = t[1].lower()`) {
|
public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) {
|
||||||
this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`;
|
this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public $2 get$1() {
|
public $2 get$1() {
|
||||||
return `!p snip.rv = t[1].lower()`;
|
return `!p snip.rv = mixedCase(t[1])`;
|
||||||
}
|
}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
52
UltiSnips/proto.snippets
Normal file
52
UltiSnips/proto.snippets
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
priority -50
|
||||||
|
|
||||||
|
global !p
|
||||||
|
from vimsnippets import complete
|
||||||
|
|
||||||
|
FIELD_TYPES = [
|
||||||
|
'double',
|
||||||
|
'float',
|
||||||
|
'int32',
|
||||||
|
'int64',
|
||||||
|
'uint32',
|
||||||
|
'uint64',
|
||||||
|
'sint32',
|
||||||
|
'sint64',
|
||||||
|
'fixed32',
|
||||||
|
'fixed64',
|
||||||
|
'sfixed32',
|
||||||
|
'sfixed64',
|
||||||
|
'bool',
|
||||||
|
'string',
|
||||||
|
'bytes']
|
||||||
|
endglobal
|
||||||
|
|
||||||
|
snippet mess "Proto message" b
|
||||||
|
// ${2:TODO(`whoami`): Describe this message.}
|
||||||
|
message ${1:Name} {
|
||||||
|
$0
|
||||||
|
|
||||||
|
// Next available id: 1
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet reqf "Required field" b
|
||||||
|
// ${4:TODO(`whoami`): Describe this field.}
|
||||||
|
optional ${1}`!p snip.rv = complete(t[1], FIELD_TYPES)` ${2:name} = ${3:1}; // Required
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet optf "Optional field" b
|
||||||
|
// ${4:TODO(`whoami`): Describe this field.}
|
||||||
|
optional ${1}`!p snip.rv = complete(t[1], FIELD_TYPES)` ${2:name} = ${3:1};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet repf "Repeated field" b
|
||||||
|
// ${4:TODO(`whoami`): Describe this field.}
|
||||||
|
repeated ${1}`!p snip.rv = complete(t[1], FIELD_TYPES)` ${2:name} = ${3:1};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet enum "Enumeration" b
|
||||||
|
// ${2:TODO(`whoami`): Describe this enum.}
|
||||||
|
enum ${1:Name} {
|
||||||
|
}
|
||||||
|
endsnippet
|
@ -34,13 +34,30 @@ global !p
|
|||||||
NORMAL = 0x1
|
NORMAL = 0x1
|
||||||
DOXYGEN = 0x2
|
DOXYGEN = 0x2
|
||||||
SPHINX = 0x3
|
SPHINX = 0x3
|
||||||
|
GOOGLE = 0x4
|
||||||
|
|
||||||
SINGLE_QUOTES = 0x1
|
SINGLE_QUOTES = 0x1
|
||||||
DOUBLE_QUOTES = 0x2
|
DOUBLE_QUOTES = 0x2
|
||||||
|
|
||||||
|
|
||||||
|
class Arg(object):
|
||||||
|
def __init__(self, arg):
|
||||||
|
self.arg = arg
|
||||||
|
self.name = arg.split('=')[0].strip()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def is_kwarg(self):
|
||||||
|
return '=' in self.arg
|
||||||
|
|
||||||
|
|
||||||
def get_args(arglist):
|
def get_args(arglist):
|
||||||
args = [arg.split('=')[0].strip() for arg in arglist.split(',') if arg]
|
args = [Arg(arg) for arg in arglist.split(',') if arg]
|
||||||
args = [arg for arg in args if arg and arg != "self"]
|
args = [arg for arg in args if arg.name != 'self']
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
@ -51,7 +68,7 @@ def get_quoting_style(snip):
|
|||||||
return SINGLE_QUOTES
|
return SINGLE_QUOTES
|
||||||
return DOUBLE_QUOTES
|
return DOUBLE_QUOTES
|
||||||
|
|
||||||
def tripple_quotes(snip):
|
def triple_quotes(snip):
|
||||||
if get_quoting_style(snip) == SINGLE_QUOTES:
|
if get_quoting_style(snip) == SINGLE_QUOTES:
|
||||||
return "'''"
|
return "'''"
|
||||||
return '"""'
|
return '"""'
|
||||||
@ -61,6 +78,7 @@ def get_style(snip):
|
|||||||
|
|
||||||
if style == "doxygen": return DOXYGEN
|
if style == "doxygen": return DOXYGEN
|
||||||
elif style == "sphinx": return SPHINX
|
elif style == "sphinx": return SPHINX
|
||||||
|
elif style == "google": return GOOGLE
|
||||||
else: return NORMAL
|
else: return NORMAL
|
||||||
|
|
||||||
|
|
||||||
@ -71,6 +89,8 @@ def format_arg(arg, style):
|
|||||||
return ":param %s: @todo" % arg
|
return ":param %s: @todo" % arg
|
||||||
elif style == NORMAL:
|
elif style == NORMAL:
|
||||||
return ":%s: @todo" % arg
|
return ":%s: @todo" % arg
|
||||||
|
elif style == GOOGLE:
|
||||||
|
return "%s (@todo): @todo" % arg
|
||||||
|
|
||||||
|
|
||||||
def format_return(style):
|
def format_return(style):
|
||||||
@ -78,19 +98,45 @@ def format_return(style):
|
|||||||
return "@return: @todo"
|
return "@return: @todo"
|
||||||
elif style in (NORMAL, SPHINX):
|
elif style in (NORMAL, SPHINX):
|
||||||
return ":returns: @todo"
|
return ":returns: @todo"
|
||||||
|
elif style == GOOGLE:
|
||||||
|
return "Returns: @todo"
|
||||||
|
|
||||||
|
|
||||||
def write_docstring_args(args, snip):
|
def write_docstring_args(args, snip):
|
||||||
if not args:
|
if not args:
|
||||||
snip.rv += ' {0}'.format(tripple_quotes(snip))
|
snip.rv += ' {0}'.format(triple_quotes(snip))
|
||||||
return
|
return
|
||||||
|
|
||||||
snip.rv += '\n' + snip.mkline('', indent='')
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
|
|
||||||
style = get_style(snip)
|
style = get_style(snip)
|
||||||
|
|
||||||
for arg in args:
|
if style == GOOGLE:
|
||||||
snip += format_arg(arg, style)
|
write_google_docstring_args(args, snip)
|
||||||
|
else:
|
||||||
|
for arg in args:
|
||||||
|
snip += format_arg(arg, style)
|
||||||
|
|
||||||
|
|
||||||
|
def write_google_docstring_args(args, snip):
|
||||||
|
kwargs = [arg for arg in args if arg.is_kwarg()]
|
||||||
|
args = [arg for arg in args if not arg.is_kwarg()]
|
||||||
|
|
||||||
|
if args:
|
||||||
|
snip += "Args:"
|
||||||
|
snip.shift()
|
||||||
|
for arg in args:
|
||||||
|
snip += format_arg(arg, GOOGLE)
|
||||||
|
snip.unshift()
|
||||||
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
|
|
||||||
|
if kwargs:
|
||||||
|
snip += "Kwargs:"
|
||||||
|
snip.shift()
|
||||||
|
for kwarg in kwargs:
|
||||||
|
snip += format_arg(kwarg, GOOGLE)
|
||||||
|
snip.unshift()
|
||||||
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
|
|
||||||
|
|
||||||
def write_init_body(args, parents, snip):
|
def write_init_body(args, parents, snip):
|
||||||
@ -120,10 +166,10 @@ endglobal
|
|||||||
snippet class "class with docstrings" b
|
snippet class "class with docstrings" b
|
||||||
class ${1:MyClass}(${2:object}):
|
class ${1:MyClass}(${2:object}):
|
||||||
|
|
||||||
`!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)`
|
`!p snip.rv = triple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = triple_quotes(snip)`
|
||||||
|
|
||||||
def __init__(self$4):
|
def __init__(self$4):
|
||||||
`!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined1.}`!p
|
`!p snip.rv = triple_quotes(snip)`${5:@todo: to be defined1.}`!p
|
||||||
snip.rv = ""
|
snip.rv = ""
|
||||||
snip >> 2
|
snip >> 2
|
||||||
|
|
||||||
@ -132,7 +178,7 @@ args = get_args(t[4])
|
|||||||
write_docstring_args(args, snip)
|
write_docstring_args(args, snip)
|
||||||
if args:
|
if args:
|
||||||
snip.rv += '\n' + snip.mkline('', indent='')
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
snip += '{0}'.format(tripple_quotes(snip))
|
snip += '{0}'.format(triple_quotes(snip))
|
||||||
|
|
||||||
write_init_body(args, t[2], snip)
|
write_init_body(args, t[2], snip)
|
||||||
`
|
`
|
||||||
@ -143,7 +189,7 @@ endsnippet
|
|||||||
snippet slotclass "class with slots and docstrings" b
|
snippet slotclass "class with slots and docstrings" b
|
||||||
class ${1:MyClass}(${2:object}):
|
class ${1:MyClass}(${2:object}):
|
||||||
|
|
||||||
`!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)`
|
`!p snip.rv = triple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = triple_quotes(snip)`
|
||||||
`!p
|
`!p
|
||||||
snip >> 1
|
snip >> 1
|
||||||
args = get_args(t[4])
|
args = get_args(t[4])
|
||||||
@ -151,7 +197,7 @@ write_slots_args(args, snip)
|
|||||||
`
|
`
|
||||||
|
|
||||||
def __init__(self$4):
|
def __init__(self$4):
|
||||||
`!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined.}`!p
|
`!p snip.rv = triple_quotes(snip)`${5:@todo: to be defined.}`!p
|
||||||
snip.rv = ""
|
snip.rv = ""
|
||||||
snip >> 2
|
snip >> 2
|
||||||
|
|
||||||
@ -160,7 +206,7 @@ args = get_args(t[4])
|
|||||||
write_docstring_args(args, snip)
|
write_docstring_args(args, snip)
|
||||||
if args:
|
if args:
|
||||||
snip.rv += '\n' + snip.mkline('', indent='')
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
snip += tripple_quotes(snip)
|
snip += triple_quotes(snip)
|
||||||
|
|
||||||
write_init_body(args, t[2], snip)
|
write_init_body(args, t[2], snip)
|
||||||
`
|
`
|
||||||
@ -353,7 +399,7 @@ snippet def "function with docstrings" b
|
|||||||
def ${1:function}(`!p
|
def ${1:function}(`!p
|
||||||
if snip.indent:
|
if snip.indent:
|
||||||
snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}):
|
snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}):
|
||||||
`!p snip.rv = tripple_quotes(snip)`${4:@todo: Docstring for $1.}`!p
|
`!p snip.rv = triple_quotes(snip)`${4:@todo: Docstring for $1.}`!p
|
||||||
snip.rv = ""
|
snip.rv = ""
|
||||||
snip >> 1
|
snip >> 1
|
||||||
|
|
||||||
@ -364,7 +410,7 @@ if args:
|
|||||||
style = get_style(snip)
|
style = get_style(snip)
|
||||||
snip += format_return(style)
|
snip += format_return(style)
|
||||||
snip.rv += '\n' + snip.mkline('', indent='')
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
snip += tripple_quotes(snip) `
|
snip += triple_quotes(snip) `
|
||||||
${0:pass}
|
${0:pass}
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
@ -390,7 +436,7 @@ endsnippet
|
|||||||
|
|
||||||
snippet rwprop "Read write property" b
|
snippet rwprop "Read write property" b
|
||||||
def ${1:name}():
|
def ${1:name}():
|
||||||
`!p snip.rv = tripple_quotes(snip) if t[2] else ''
|
`!p snip.rv = triple_quotes(snip) if t[2] else ''
|
||||||
`${2:@todo: Docstring for $1.}`!p
|
`${2:@todo: Docstring for $1.}`!p
|
||||||
if t[2]:
|
if t[2]:
|
||||||
snip >> 1
|
snip >> 1
|
||||||
@ -399,7 +445,7 @@ if t[2]:
|
|||||||
snip.rv += '\n' + snip.mkline('', indent='')
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
snip += format_return(style)
|
snip += format_return(style)
|
||||||
snip.rv += '\n' + snip.mkline('', indent='')
|
snip.rv += '\n' + snip.mkline('', indent='')
|
||||||
snip += tripple_quotes(snip)
|
snip += triple_quotes(snip)
|
||||||
else:
|
else:
|
||||||
snip.rv = ""`
|
snip.rv = ""`
|
||||||
def fget(self):
|
def fget(self):
|
||||||
@ -518,7 +564,7 @@ endsnippet
|
|||||||
snippet testcase "pyunit testcase" b
|
snippet testcase "pyunit testcase" b
|
||||||
class Test${1:Class}(${2:unittest.TestCase}):
|
class Test${1:Class}(${2:unittest.TestCase}):
|
||||||
|
|
||||||
`!p snip.rv = tripple_quotes(snip)`${3:Test case docstring.}`!p snip.rv = tripple_quotes(snip)`
|
`!p snip.rv = triple_quotes(snip)`${3:Test case docstring.}`!p snip.rv = triple_quotes(snip)`
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
${4:pass}
|
${4:pass}
|
||||||
|
144
UltiSnips/r.snippets
Normal file
144
UltiSnips/r.snippets
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
priority -50
|
||||||
|
|
||||||
|
snippet #! "Hashbang for Rscript (#!)" b
|
||||||
|
#!/usr/bin/env Rscript
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet lib "Import a library"
|
||||||
|
library(${0:package})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet req "Require a file"
|
||||||
|
require(${0:package})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet source "Source a file"
|
||||||
|
source('${0:file}')
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet if "If statement"
|
||||||
|
if (${1}) {
|
||||||
|
${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet eif "Else-If statement"
|
||||||
|
else if (${1}) {
|
||||||
|
${0}
|
||||||
|
}
|
||||||
|
|
||||||
|
snippet el "Else statement"
|
||||||
|
else {
|
||||||
|
${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet ife "if .. else"
|
||||||
|
if (${1}) {
|
||||||
|
${2}
|
||||||
|
} else {
|
||||||
|
${3}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet wh "while loop"
|
||||||
|
while(${1}) {
|
||||||
|
${2}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet for "for loop"
|
||||||
|
for ({${1:item} in ${2:list}) {
|
||||||
|
${3}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet fun "Function definition"
|
||||||
|
${1:name} <- function (${2}) {
|
||||||
|
${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet ret "Return call"
|
||||||
|
return(${0})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet df "Data frame"
|
||||||
|
${1:name}[${2:rows}, ${0:cols}]
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet c "c function"
|
||||||
|
c(${0:items})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet li "list function"
|
||||||
|
list(${0:items})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet mat "matrix function"
|
||||||
|
matrix(${1:data}, nrow = ${2:rows}, ncol = ${0:cols})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet apply "apply function"
|
||||||
|
apply(${1:array}, ${2:margin}, ${0:function})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet lapply "lapply function"
|
||||||
|
lapply(${1:list}, ${0:function})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet sapply "sapply function"
|
||||||
|
lapply(${1:list}, ${0:function})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet vapply "vapply function"
|
||||||
|
vapply(${1:list}, ${2:function}, ${0:type})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet mapply "mapply function"
|
||||||
|
mapply(${1:function}, ${0:...})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet tapply "tapply function"
|
||||||
|
tapply(${1:vector}, ${2:index}, ${0:function})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet rapply "rapply function"
|
||||||
|
rapply(${1:list}, ${0:function})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet pl "Plot function"
|
||||||
|
plot(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet ggp "ggplot2 plot"
|
||||||
|
ggplot(${1:data}, aes(${0:aesthetics}))
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet fis "Fisher test"
|
||||||
|
fisher.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet chi "Chi Squared test"
|
||||||
|
chisq.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet tt "t-test"
|
||||||
|
t.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet wil "Wilcox test"
|
||||||
|
wilcox.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet cor "Correlation test"
|
||||||
|
cor.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet fte "FTE test"
|
||||||
|
var.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet kvt "KV test"
|
||||||
|
kv.test(${1:x}, ${0:y})
|
||||||
|
endsnippet
|
3
UltiSnips/rnoweb.snippets
Normal file
3
UltiSnips/rnoweb.snippets
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
priority -50
|
||||||
|
|
||||||
|
extends tex, r
|
@ -12,6 +12,8 @@ from string import Template
|
|||||||
import re
|
import re
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
|
from vimsnippets import complete
|
||||||
|
|
||||||
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
|
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
|
||||||
TEXT_ROLES = ['emphasis','literal','code','math',
|
TEXT_ROLES = ['emphasis','literal','code','math',
|
||||||
'pep-reference','rfc-reference',
|
'pep-reference','rfc-reference',
|
||||||
@ -130,27 +132,6 @@ def get_popular_code_type():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
popular_type = "lua" # Don't break default
|
popular_type = "lua" # Don't break default
|
||||||
return popular_type
|
return popular_type
|
||||||
|
|
||||||
|
|
||||||
def complete(t, opts):
|
|
||||||
"""
|
|
||||||
get options that start with t
|
|
||||||
|
|
||||||
:param t: query string
|
|
||||||
:param opts: list that needs to be completed
|
|
||||||
|
|
||||||
:return: a string that start with t
|
|
||||||
"""
|
|
||||||
msg = "({0})"
|
|
||||||
if t:
|
|
||||||
opts = [ m[len(t):] for m in opts if m.startswith(t) ]
|
|
||||||
if len(opts) == 1:
|
|
||||||
return opts[0]
|
|
||||||
|
|
||||||
if not len(opts):
|
|
||||||
msg = "{0}"
|
|
||||||
return msg.format("|".join(opts))
|
|
||||||
|
|
||||||
endglobal
|
endglobal
|
||||||
|
|
||||||
snippet part "Part" b
|
snippet part "Part" b
|
||||||
|
215
UltiSnips/rust.snippets
Normal file
215
UltiSnips/rust.snippets
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
#######################################################################
|
||||||
|
# Rust Snippets #
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
###############
|
||||||
|
# Functions #
|
||||||
|
###############
|
||||||
|
snippet fn "A function, optionally with arguments and return type."
|
||||||
|
fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet test "Test function"
|
||||||
|
#[test]
|
||||||
|
fn ${1:test_function_name}() {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet new "A new function"
|
||||||
|
pub fn new(${2}) -> ${1:Name} {
|
||||||
|
${VISUAL}${0}return $1 { ${3} };
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet main "The main function"
|
||||||
|
pub fn main() {
|
||||||
|
${VISUAL}${0}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
snippet let "A let statement"
|
||||||
|
let ${1:name}${3} = ${VISUAL}${2};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet pln "println!(..)" b
|
||||||
|
println!("${1}"${2/..*/, /}${2});
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
snippet ec "extern crate ..." b
|
||||||
|
extern crate ${1:sync};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet ecl "...extern crate log;" b
|
||||||
|
#![feature(phase)]
|
||||||
|
#[phase(syntax, link)] extern crate log;
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet mod "A mod." b
|
||||||
|
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
} /* $1 */
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet crate "Create header information" b
|
||||||
|
// Crate ID
|
||||||
|
#![crate_id = "${1:crate_name}#${2:0.0.1}"]
|
||||||
|
|
||||||
|
// Additional metadata attributes
|
||||||
|
#![desc = "${3:Descrption.}"]
|
||||||
|
#![license = "${4:BSD}"]
|
||||||
|
#![comment = "${5:Comment.}"]
|
||||||
|
|
||||||
|
// Specify the output type
|
||||||
|
#![crate_type = "${6:lib}"]
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet allow "#[allow(..)]" b
|
||||||
|
#[allow(${1:unused_variable})]
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet feat "#![feature(..)]" b
|
||||||
|
#![feature(${1:macro_rules})]
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
##################
|
||||||
|
# Common types #
|
||||||
|
##################
|
||||||
|
snippet opt "Option<..>"
|
||||||
|
Option<${1:int}>
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet res "Result<.., ..>"
|
||||||
|
Result<${1:~str}, ${2:()}>
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
snippet if "if .. (if)" b
|
||||||
|
if ${1:/* condition */} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet mat "match"
|
||||||
|
match ${1} {
|
||||||
|
${2} => ${3},
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet while "while .. {}" b
|
||||||
|
while ${1:condition} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet for "for .. in .." b
|
||||||
|
for ${1:i} in ${2:range(0u, 10)} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet spawn "spawn(proc() { .. });" b
|
||||||
|
spawn(proc() {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
});
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet chan "A channel" b
|
||||||
|
let (${1:tx}, ${2:rx}): (Sender<${3:int}>, Receiver<${4:int}>) = channel();
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet duplex "Duplex stream" b
|
||||||
|
let (${1:from_child}, ${2:to_child}) = sync::duplex();
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# TODO commenting #
|
||||||
|
#####################
|
||||||
|
snippet todo "A Todo comment"
|
||||||
|
// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")`
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
############
|
||||||
|
# Struct #
|
||||||
|
############
|
||||||
|
snippet st "Struct" b
|
||||||
|
struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet stn "Struct with new constructor." b
|
||||||
|
pub struct ${1:`!p snip.rv = snip.basename.title() or "name"`} {
|
||||||
|
${3:/* code */}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $1 {
|
||||||
|
pub fn new(${2}) -> $1 {
|
||||||
|
${4}return $1 {
|
||||||
|
${5}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
##########
|
||||||
|
# Enum #
|
||||||
|
##########
|
||||||
|
snippet enum "An enum" b
|
||||||
|
enum ${1:enum_name} {
|
||||||
|
${VISUAL}${0},
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
##########
|
||||||
|
# Impl #
|
||||||
|
##########
|
||||||
|
snippet imp "An impl" b
|
||||||
|
impl ${1:Name} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet drop "Drop implementation" b
|
||||||
|
impl Drop for ${1:Name} {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
############
|
||||||
|
# Traits #
|
||||||
|
############
|
||||||
|
snippet trait "Trait block" b
|
||||||
|
trait ${1:Name} {
|
||||||
|
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
|
||||||
|
}
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
|
||||||
|
#############
|
||||||
|
# Statics #
|
||||||
|
#############
|
||||||
|
snippet ss "A static string."
|
||||||
|
static ${1}: &'static str = "${VISUAL}${0}";
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
snippet stat "A static variable."
|
||||||
|
static ${1}: ${2:uint} = ${VISUAL}${0};
|
||||||
|
endsnippet
|
||||||
|
|
||||||
|
# vim:ft=snippets:
|
37
plugin/vimsnippets.vim
Normal file
37
plugin/vimsnippets.vim
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
if exists("b:done_vimsnippets")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:done_vimsnippets = 1
|
||||||
|
|
||||||
|
" Expanding the path is not needed on Vim 7.4
|
||||||
|
if &cp || version >= 704
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Add pythonx to the python search path if needed (i.e. <= Vim 7.3).
|
||||||
|
if !has("python") && !has("python3")
|
||||||
|
finish
|
||||||
|
end
|
||||||
|
|
||||||
|
" This will fail if UltiSnips is not installed.
|
||||||
|
try
|
||||||
|
call UltiSnips#bootstrap#Bootstrap()
|
||||||
|
catch /E117/
|
||||||
|
finish
|
||||||
|
endtry
|
||||||
|
|
||||||
|
|
||||||
|
" This should have been set by UltiSnips, otherwise something is wrong.
|
||||||
|
if !exists("g:_uspy")
|
||||||
|
finish
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
" Expand our path
|
||||||
|
let s:SourcedFile=expand("<sfile>")
|
||||||
|
exec g:_uspy "import vim, os, sys"
|
||||||
|
exec g:_uspy "sourced_file = vim.eval('s:SourcedFile')"
|
||||||
|
exec g:_uspy "while not os.path.exists(os.path.join(sourced_file, 'pythonx')):
|
||||||
|
\ sourced_file = os.path.dirname(sourced_file)"
|
||||||
|
exec g:_uspy "module_path = os.path.join(sourced_file, 'pythonx')"
|
||||||
|
exec g:_uspy "sys.path.append(module_path)"
|
20
pythonx/vimsnippets.py
Normal file
20
pythonx/vimsnippets.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""Helper methods used in UltiSnips snippets."""
|
||||||
|
|
||||||
|
def complete(tab, opts):
|
||||||
|
"""
|
||||||
|
get options that start with tab
|
||||||
|
|
||||||
|
:param tab: query string
|
||||||
|
:param opts: list that needs to be completed
|
||||||
|
|
||||||
|
:return: a string that start with tab
|
||||||
|
"""
|
||||||
|
msg = "({0})"
|
||||||
|
if tab:
|
||||||
|
opts = [m[len(tab):] for m in opts if m.startswith(tab)]
|
||||||
|
if len(opts) == 1:
|
||||||
|
return opts[0]
|
||||||
|
|
||||||
|
if not len(opts):
|
||||||
|
msg = "{0}"
|
||||||
|
return msg.format("|".join(opts))
|
@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
snippet auto
|
snippet auto
|
||||||
${1:FIELDNAME} = models.AutoField(${0})
|
${1:FIELDNAME} = models.AutoField(${0})
|
||||||
|
snippet bigint
|
||||||
|
${1:FIELDNAME} = models.BigIntegerField(${0})
|
||||||
|
snippet binary
|
||||||
|
${1:FIELDNAME} = models.BinaryField(${0})
|
||||||
snippet bool
|
snippet bool
|
||||||
${1:FIELDNAME} = models.BooleanField(${0:default=True})
|
${1:FIELDNAME} = models.BooleanField(${0:default=True})
|
||||||
snippet char
|
snippet char
|
||||||
@ -80,7 +84,7 @@ snippet model
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
${5}
|
${5}
|
||||||
|
|
||||||
def save(self, force_insert=False, force_update=False):
|
def save(self, *args, **kwargs):
|
||||||
${6}
|
${6}
|
||||||
|
|
||||||
@models.permalink
|
@models.permalink
|
||||||
|
@ -120,8 +120,12 @@ snippet gen_server
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1,
|
||||||
terminate/2, code_change/3]).
|
handle_call/3,
|
||||||
|
handle_cast/2,
|
||||||
|
handle_info/2,
|
||||||
|
terminate/2,
|
||||||
|
code_change/3]).
|
||||||
|
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
|
|
||||||
@ -157,6 +161,320 @@ snippet gen_server
|
|||||||
code_change(_OldVsn, State, _Extra) ->
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Internal functions
|
||||||
|
%%%===================================================================
|
||||||
|
# OTP gen_fsm
|
||||||
|
snippet gen_fsm
|
||||||
|
-module(${0:`vim_snippets#Filename('', 'my')`}).
|
||||||
|
|
||||||
|
-behaviour(gen_fsm).
|
||||||
|
|
||||||
|
%% API
|
||||||
|
-export([start_link/0]).
|
||||||
|
|
||||||
|
%% gen_fsm callbacks
|
||||||
|
-export([init/1,
|
||||||
|
state_name/2,
|
||||||
|
state_name/3,
|
||||||
|
handle_event/3,
|
||||||
|
handle_sync_event/4,
|
||||||
|
handle_info/3,
|
||||||
|
terminate/3,
|
||||||
|
code_change/4]).
|
||||||
|
|
||||||
|
-record(state, {}).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% API
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Creates a gen_fsm process which calls Module:init/1 to
|
||||||
|
%% initialize. To ensure a synchronized start-up procedure, this
|
||||||
|
%% function does not return until Module:init/1 has returned.
|
||||||
|
%%
|
||||||
|
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
start_link() ->
|
||||||
|
gen_fsm:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% gen_fsm callbacks
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or
|
||||||
|
%% gen_fsm:start_link/[3,4], this function is called by the new
|
||||||
|
%% process to initialize.
|
||||||
|
%%
|
||||||
|
%% @spec init(Args) -> {ok, StateName, State} |
|
||||||
|
%% {ok, StateName, State, Timeout} |
|
||||||
|
%% ignore |
|
||||||
|
%% {stop, StopReason}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
init([]) ->
|
||||||
|
{ok, state_name, #state{}}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% There should be one instance of this function for each possible
|
||||||
|
%% state name. Whenever a gen_fsm receives an event sent using
|
||||||
|
%% gen_fsm:send_event/2, the instance of this function with the same
|
||||||
|
%% name as the current state name StateName is called to handle
|
||||||
|
%% the event. It is also called if a timeout occurs.
|
||||||
|
%%
|
||||||
|
%% @spec state_name(Event, State) ->
|
||||||
|
%% {next_state, NextStateName, NextState} |
|
||||||
|
%% {next_state, NextStateName, NextState, Timeout} |
|
||||||
|
%% {stop, Reason, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
state_name(_Event, State) ->
|
||||||
|
{next_state, state_name, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% There should be one instance of this function for each possible
|
||||||
|
%% state name. Whenever a gen_fsm receives an event sent using
|
||||||
|
%% gen_fsm:sync_send_event/[2,3], the instance of this function with
|
||||||
|
%% the same name as the current state name StateName is called to
|
||||||
|
%% handle the event.
|
||||||
|
%%
|
||||||
|
%% @spec state_name(Event, From, State) ->
|
||||||
|
%% {next_state, NextStateName, NextState} |
|
||||||
|
%% {next_state, NextStateName, NextState, Timeout} |
|
||||||
|
%% {reply, Reply, NextStateName, NextState} |
|
||||||
|
%% {reply, Reply, NextStateName, NextState, Timeout} |
|
||||||
|
%% {stop, Reason, NewState} |
|
||||||
|
%% {stop, Reason, Reply, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
state_name(_Event, _From, State) ->
|
||||||
|
Reply = ok,
|
||||||
|
{reply, Reply, state_name, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever a gen_fsm receives an event sent using
|
||||||
|
%% gen_fsm:send_all_state_event/2, this function is called to handle
|
||||||
|
%% the event.
|
||||||
|
%%
|
||||||
|
%% @spec handle_event(Event, StateName, State) ->
|
||||||
|
%% {next_state, NextStateName, NextState} |
|
||||||
|
%% {next_state, NextStateName, NextState, Timeout} |
|
||||||
|
%% {stop, Reason, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
handle_event(_Event, StateName, State) ->
|
||||||
|
{next_state, StateName, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever a gen_fsm receives an event sent using
|
||||||
|
%% gen_fsm:sync_send_all_state_event/[2,3], this function is called
|
||||||
|
%% to handle the event.
|
||||||
|
%%
|
||||||
|
%% @spec handle_sync_event(Event, From, StateName, State) ->
|
||||||
|
%% {next_state, NextStateName, NextState} |
|
||||||
|
%% {next_state, NextStateName, NextState, Timeout} |
|
||||||
|
%% {reply, Reply, NextStateName, NextState} |
|
||||||
|
%% {reply, Reply, NextStateName, NextState, Timeout} |
|
||||||
|
%% {stop, Reason, NewState} |
|
||||||
|
%% {stop, Reason, Reply, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
handle_sync_event(_Event, _From, StateName, State) ->
|
||||||
|
Reply = ok,
|
||||||
|
{reply, Reply, StateName, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% This function is called by a gen_fsm when it receives any
|
||||||
|
%% message other than a synchronous or asynchronous event
|
||||||
|
%% (or a system message).
|
||||||
|
%%
|
||||||
|
%% @spec handle_info(Info,StateName,State)->
|
||||||
|
%% {next_state, NextStateName, NextState} |
|
||||||
|
%% {next_state, NextStateName, NextState, Timeout} |
|
||||||
|
%% {stop, Reason, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
handle_info(_Info, StateName, State) ->
|
||||||
|
{next_state, StateName, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% This function is called by a gen_fsm when it is about to
|
||||||
|
%% terminate. It should be the opposite of Module:init/1 and do any
|
||||||
|
%% necessary cleaning up. When it returns, the gen_fsm terminates with
|
||||||
|
%% Reason. The return value is ignored.
|
||||||
|
%%
|
||||||
|
%% @spec terminate(Reason, StateName, State) -> void()
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
terminate(_Reason, _StateName, _State) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Convert process state when code is changed
|
||||||
|
%%
|
||||||
|
%% @spec code_change(OldVsn, StateName, State, Extra) ->
|
||||||
|
%% {ok, StateName, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
code_change(_OldVsn, StateName, State, _Extra) ->
|
||||||
|
{ok, StateName, State}.
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Internal functions
|
||||||
|
%%%===================================================================
|
||||||
|
# OTP gen_event
|
||||||
|
snippet gen_event
|
||||||
|
-module(${0:`vim_snippets#Filename('', 'my')`}).
|
||||||
|
|
||||||
|
-behaviour(gen_event).
|
||||||
|
|
||||||
|
%% API
|
||||||
|
-export([start_link/0,
|
||||||
|
add_handler/2]).
|
||||||
|
|
||||||
|
%% gen_event callbacks
|
||||||
|
-export([init/1,
|
||||||
|
handle_event/2,
|
||||||
|
handle_call/2,
|
||||||
|
handle_info/2,
|
||||||
|
terminate/2,
|
||||||
|
code_change/3]).
|
||||||
|
|
||||||
|
-record(state, {}).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% gen_event callbacks
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Creates an event manager
|
||||||
|
%%
|
||||||
|
%% @spec start_link() -> {ok, Pid} | {error, Error}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
start_link() ->
|
||||||
|
gen_event:start_link({local, ?MODULE}).
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Adds an event handler
|
||||||
|
%%
|
||||||
|
%% @spec add_handler(Handler, Args) -> ok | {'EXIT', Reason} | term()
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
add_handler(Handler, Args) ->
|
||||||
|
gen_event:add_handler(?MODULE, Handler, Args).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% gen_event callbacks
|
||||||
|
%%%===================================================================
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever a new event handler is added to an event manager,
|
||||||
|
%% this function is called to initialize the event handler.
|
||||||
|
%%
|
||||||
|
%% @spec init(Args) -> {ok, State}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
init([]) ->
|
||||||
|
{ok, #state{}}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever an event manager receives an event sent using
|
||||||
|
%% gen_event:notify/2 or gen_event:sync_notify/2, this function is
|
||||||
|
%% called for each installed event handler to handle the event.
|
||||||
|
%%
|
||||||
|
%% @spec handle_event(Event, State) ->
|
||||||
|
%% {ok, State} |
|
||||||
|
%% {swap_handler, Args1, State1, Mod2, Args2} |
|
||||||
|
%% remove_handler
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
handle_event(_Event, State) ->
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever an event manager receives a request sent using
|
||||||
|
%% gen_event:call/3,4, this function is called for the specified
|
||||||
|
%% event handler to handle the request.
|
||||||
|
%%
|
||||||
|
%% @spec handle_call(Request, State) ->
|
||||||
|
%% {ok, Reply, State} |
|
||||||
|
%% {swap_handler, Reply, Args1, State1, Mod2, Args2} |
|
||||||
|
%% {remove_handler, Reply}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
handle_call(_Request, State) ->
|
||||||
|
Reply = ok,
|
||||||
|
{ok, Reply, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% This function is called for each installed event handler when
|
||||||
|
%% an event manager receives any other message than an event or a
|
||||||
|
%% synchronous request (or a system message).
|
||||||
|
%%
|
||||||
|
%% @spec handle_info(Info, State) ->
|
||||||
|
%% {ok, State} |
|
||||||
|
%% {swap_handler, Args1, State1, Mod2, Args2} |
|
||||||
|
%% remove_handler
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
handle_info(_Info, State) ->
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Whenever an event handler is deleted from an event manager, this
|
||||||
|
%% function is called. It should be the opposite of Module:init/1 and
|
||||||
|
%% do any necessary cleaning up.
|
||||||
|
%%
|
||||||
|
%% @spec terminate(Reason, State) -> void()
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
terminate(_Reason, _State) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% @private
|
||||||
|
%% @doc
|
||||||
|
%% Convert process state when code is changed
|
||||||
|
%%
|
||||||
|
%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState}
|
||||||
|
%% @end
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
code_change(_OldVsn, State, _Extra) ->
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
@ -107,6 +107,8 @@ snippet ntc
|
|||||||
<%= number_to_currency(${1}) %>
|
<%= number_to_currency(${1}) %>
|
||||||
snippet ofcfs
|
snippet ofcfs
|
||||||
<%= options_from_collection_for_select ${1:collection}, ${2:value_method}, ${3:text_method}, ${0:selected_value} %>
|
<%= options_from_collection_for_select ${1:collection}, ${2:value_method}, ${3:text_method}, ${0:selected_value} %>
|
||||||
|
snippet ofs
|
||||||
|
<%= options_for_select ${1:collection}, ${2:value_method} %>
|
||||||
snippet rf
|
snippet rf
|
||||||
<%= render :file => "${1:file}"${0} %>
|
<%= render :file => "${1:file}"${0} %>
|
||||||
snippet rt
|
snippet rt
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
snippet lang
|
snippet lang
|
||||||
{-# LANGUAGE ${0:OverloadedStrings} #-}
|
{-# LANGUAGE ${0:OverloadedStrings} #-}
|
||||||
|
snippet haddock
|
||||||
|
{-# OPTIONS_HADDOCK ${0:hide} #-}
|
||||||
snippet info
|
snippet info
|
||||||
-- |
|
-- |
|
||||||
-- Module : ${1:Module.Namespace}
|
-- Module : ${1:Module.Namespace}
|
||||||
|
18
snippets/jade.snippets
Normal file
18
snippets/jade.snippets
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Angular HTML
|
||||||
|
snippet rep
|
||||||
|
div(ng-repeat='${1} in ${2}')
|
||||||
|
|
||||||
|
snippet repf
|
||||||
|
div(ng-repeat='${1} in ${2}' | ${3})
|
||||||
|
|
||||||
|
snippet repi
|
||||||
|
div(ng-repeat='${1} in ${2}' track by $index)
|
||||||
|
|
||||||
|
snippet hide
|
||||||
|
div(ng-hide='${1}')
|
||||||
|
|
||||||
|
snippet show
|
||||||
|
div(ng-show='${1}')
|
||||||
|
|
||||||
|
snippet if
|
||||||
|
div(ng-if='${1}')
|
@ -1,5 +1,6 @@
|
|||||||
snippet #!
|
snippet #!
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
snippet imp
|
snippet imp
|
||||||
import ${0:module}
|
import ${0:module}
|
||||||
snippet uni
|
snippet uni
|
||||||
@ -200,3 +201,10 @@ snippet epydoc
|
|||||||
|
|
||||||
@raise e: ${0: Description}
|
@raise e: ${0: Description}
|
||||||
"""
|
"""
|
||||||
|
snippet dol
|
||||||
|
def ${1:__init__}(self, *args, **kwargs):
|
||||||
|
super(${0:ClassName}, self).$1(*args, **kwargs)
|
||||||
|
snippet kwg
|
||||||
|
self.${1:var_name} = kwargs.get('$1', ${2:None})
|
||||||
|
snippet lkwg
|
||||||
|
${1:var_name} = kwargs.get('$1', ${2:None})
|
||||||
|
@ -479,6 +479,8 @@ snippet asne
|
|||||||
assert_not_equal ${1:unexpected}, ${2:actual}
|
assert_not_equal ${1:unexpected}, ${2:actual}
|
||||||
snippet asid
|
snippet asid
|
||||||
assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2 ** -20}
|
assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2 ** -20}
|
||||||
|
snippet asi
|
||||||
|
assert_includes ${1:collection}, ${2:object}
|
||||||
snippet asio
|
snippet asio
|
||||||
assert_instance_of ${1:ExpectedClass}, ${2:actual_instance}
|
assert_instance_of ${1:ExpectedClass}, ${2:actual_instance}
|
||||||
snippet asko
|
snippet asko
|
||||||
@ -749,8 +751,49 @@ snippet mapwo
|
|||||||
${1:map}.with_options :${2:controller} => '${3:thing}' do |$3|
|
${1:map}.with_options :${2:controller} => '${3:thing}' do |$3|
|
||||||
${0}
|
${0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# model callback snippets #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
# before callback
|
||||||
|
snippet mbv
|
||||||
|
before_validation :${0:method}
|
||||||
|
snippet mbc
|
||||||
|
before_create :${0:method}
|
||||||
|
snippet mbu
|
||||||
|
before_update :${0:method}
|
||||||
snippet mbs
|
snippet mbs
|
||||||
before_save :${0:method}
|
before_save :${0:method}
|
||||||
|
snippet mbd
|
||||||
|
before_destroy :${0:method}
|
||||||
|
|
||||||
|
# after callback
|
||||||
|
snippet mav
|
||||||
|
after_validation :${0:method}
|
||||||
|
snippet maf
|
||||||
|
after_find :${0:method}
|
||||||
|
snippet mat
|
||||||
|
after_touch :${0:method}
|
||||||
|
snippet macr
|
||||||
|
after_create :${0:method}
|
||||||
|
snippet mau
|
||||||
|
after_update :${0:method}
|
||||||
|
snippet mas
|
||||||
|
after_save :${0:method}
|
||||||
|
snippet mad
|
||||||
|
after_destroy :${0:method}
|
||||||
|
|
||||||
|
# around callback
|
||||||
|
snippet marc
|
||||||
|
around_create :${0:method}
|
||||||
|
snippet maru
|
||||||
|
around_update :${0:method}
|
||||||
|
snippet mars
|
||||||
|
around_save :${0:method}
|
||||||
|
snippet mard
|
||||||
|
around_destroy :${0:method}
|
||||||
|
|
||||||
snippet mcht
|
snippet mcht
|
||||||
change_table :${1:table_name} do |t|
|
change_table :${1:table_name} do |t|
|
||||||
${0}
|
${0}
|
||||||
|
@ -194,8 +194,9 @@ snippet mhmap
|
|||||||
snippet as
|
snippet as
|
||||||
${1:name}.asInstanceOf[${2:T}]
|
${1:name}.asInstanceOf[${2:T}]
|
||||||
#isInstanceOf[]
|
#isInstanceOf[]
|
||||||
|
snippet is
|
||||||
${1:name}.isInstanceOf[${2:T}]
|
${1:name}.isInstanceOf[${2:T}]
|
||||||
#end
|
|
||||||
#collections methods
|
#collections methods
|
||||||
|
|
||||||
#scope() with one arg
|
#scope() with one arg
|
||||||
|
Loading…
Reference in New Issue
Block a user