1
0
mirror of https://github.com/amix/vimrc synced 2025-07-12 22:24:59 +08:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Mirosław Pragłowski
2014-10-13 21:54:40 +02:00
266 changed files with 11284 additions and 3954 deletions

View File

@ -120,4 +120,14 @@ vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.
endsnippet
##########################
# VIM MODELINE GENERATOR #
##########################
# See advice on `:help 'tabstop'` for why these values are set. Uses second
# modeline form ('set') to work in languages with comment terminators
# (/* like C */).
snippet modeline "Vim modeline"
vim`!v ':set '. (&expandtab ? printf('et sw=%i ts=%i', &sw, &ts) : printf('noet sts=%i sw=%i ts=%i', &sts, &sw, &ts)) . (&tw ? ' tw='. &tw : '') . ':'`
endsnippet
# vim:ft=snippets:

View File

@ -16,7 +16,7 @@ endsnippet
snippet #if "#if #endif" b
#if ${1:0}
${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}}
${VISUAL}${0}
#endif
endsnippet
@ -40,7 +40,7 @@ endsnippet
snippet main "main() (main)"
int main(int argc, char *argv[])
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
return 0;
}
endsnippet
@ -48,14 +48,14 @@ endsnippet
snippet for "for loop (for)"
for (${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet
snippet fori "for int loop (fori)"
for (${4:int} ${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet
@ -74,10 +74,9 @@ else:
snip.rv = snip.c`}
#define $1
${0}
${VISUAL}${0}
#endif /* end of include guard: $1 */
endsnippet
snippet td "Typedef"
@ -86,13 +85,13 @@ endsnippet
snippet wh "while loop"
while(${1:/* condition */}) {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet
snippet do "do...while loop (do)"
do {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
} while(${1:/* condition */});
endsnippet
@ -103,26 +102,26 @@ endsnippet
snippet if "if .. (if)"
if (${1:/* condition */})
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet
snippet el "else .. (else)"
else {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet
snippet eli "else if .. (eli)"
else if (${1:/* condition */}) {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet
snippet ife "if .. else (ife)"
if (${1:/* condition */})
{
${2:/* code */}
${2}
}
else
{
@ -144,7 +143,7 @@ endsnippet
snippet fun "function" b
${1:void} ${2:function_name}(${3})
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}
endsnippet

View File

@ -27,7 +27,7 @@ endsnippet
snippet ns "namespace .. (namespace)"
namespace${1/.+/ /m}${1:`!p snip.rv = snip.basename or "name"`}
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
${VISUAL}${0}
}${1/.+/ \/* /m}$1${1/.+/ *\/ /m}
endsnippet

View File

@ -106,14 +106,14 @@ endsnippet
snippet if "if .. (if)"
if(${1:/*condition*/})
{
${VISUAL}${0:/*code*/}
${VISUAL}${0}
}
endsnippet
snippet ife "if .. else (ife)" b
if(${1:/*condition*/})
{
${2:/*code*/}
${2}
}
else
{
@ -124,14 +124,14 @@ endsnippet
snippet el "else (el)" b
else
{
${VISUAL}${1:/*code*/}
${VISUAL}${1}
}
endsnippet
snippet elif "else if (elif)" b
else if(${1:/*condition*/})
{
${VISUAL}${0:/*code*/}
${VISUAL}${0}
}
endsnippet
@ -139,10 +139,10 @@ snippet sw "switch (sw)"
switch(${1:/*var*/})
{
case ${2:/*value*/}:
${3:/*code*/}
${3}
break;
case ${4:/*value*/}:
${5:/*code*/}
${5}
break;
${7:/*more cases*/}
default:
@ -151,13 +151,13 @@ switch(${1:/*var*/})
endsnippet
snippet fsw "final switch (fsw)"
switch(${1:/*var*/})
final switch(${1:/*var*/})
{
case ${2:/*value*/}:
${3:/*code*/}
${3}
break;
case ${4:/*value*/}:
${5:/*code*/}
${5}
break;
${7:/*more cases*/}
}
@ -165,7 +165,7 @@ endsnippet
snippet case "case (case)" b
case ${1:/*value*/}:
${2:/*code*/}
${2}
break;
endsnippet
@ -178,42 +178,42 @@ endsnippet
snippet do "do while (do)" b
do
{
${VISUAL}${2:/*code*/}
${VISUAL}${2}
} while(${1:/*condition*/});
endsnippet
snippet wh "while (wh)" b
while(${1:/*condition*/})
{
${VISUAL}${2:/*code*/}
${VISUAL}${2}
}
endsnippet
snippet for "for (for)" b
for (${4:size_t} ${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
${VISUAL}${0:/*code*/}
${VISUAL}${0}
}
endsnippet
snippet forever "forever (forever)" b
for(;;)
{
${VISUAL}${0:/*code*/}
${VISUAL}${0}
}
endsnippet
snippet fore "foreach (fore)"
foreach(${1:/*elem*/}; ${2:/*range*/})
{
${VISUAL}${3:/*code*/}
${VISUAL}${3}
}
endsnippet
snippet forif "foreach if (forif)" b
foreach(${1:/*elem*/}; ${2:/*range*/}) if(${3:/*condition*/})
{
${VISUAL}${4:/*code*/}
${VISUAL}${4}
}
endsnippet
@ -249,21 +249,21 @@ endsnippet
snippet fun "function definition (fun)"
${1:void} ${2:/*function name*/}(${3:/*args*/}) ${4:@safe pure nothrow}
{
${VISUAL}${5:/*code*/}
${VISUAL}${5}
}
endsnippet
snippet void "void function definition (void)"
void ${1:/*function name*/}(${2:/*args*/}) ${3:@safe pure nothrow}
{
${VISUAL}${4:/*code*/}
${VISUAL}${4}
}
endsnippet
snippet this "ctor (this)" w
this(${1:/*args*/})
{
${VISUAL}${2:/*code*/}
${VISUAL}${2}
}
endsnippet
@ -295,7 +295,7 @@ endsnippet
snippet scope "scope (scope)" b
scope(${1:exit})
{
${VISUAL}${2:/*code*/}
${VISUAL}${2}
}
endsnippet
@ -304,7 +304,7 @@ endsnippet
snippet with "with (with)"
with(${1})
{
${VISUAL}${2:/*code*/}
${VISUAL}${2}
}
endsnippet
@ -405,14 +405,14 @@ endsnippet
snippet version "version (version)" b
version(${1:/*version name*/})
{
${VISUAL}${2:/*code*/}
${VISUAL}${2}
}
endsnippet
snippet debug "debug" b
debug
{
${VISUAL}${1:/*code*/}
${VISUAL}${1}
}
endsnippet
@ -422,7 +422,7 @@ endsnippet
snippet temp "template (temp)" b
template ${2:/*name*/}(${1:/*args*/})
{
${3:/*code*/}
${3}
}
endsnippet
@ -440,7 +440,7 @@ endsnippet
snippet unittest "unittest (unittest)" b
unittest
{
${1:/*code*/}
${1}
}
endsnippet
@ -450,21 +450,21 @@ endsnippet
snippet opDis "opDispatch (opDis)" b
${1:/*return type*/} opDispatch(string s)()
{
${2:/*code*/};
${2};
}
endsnippet
snippet op= "opAssign (op=)" b
void opAssign(${1} rhs) ${2:@safe pure nothrow}
{
${2:/*code*/}
${2}
}
endsnippet
snippet opCmp "opCmp (opCmp)" b
int opCmp(${1} rhs) @safe const pure nothrow
{
${2:/*code*/}
${2}
}
endsnippet
@ -484,7 +484,7 @@ endsnippet
snippet toString "toString (toString)" b
string toString() @safe const pure nothrow
{
${1:/*code*/}
${1}
}
endsnippet

View File

@ -1,3 +1,5 @@
extends html
priority -50
# TextMate added these variables to cope with changes in ERB handling

View File

@ -52,6 +52,12 @@ for ${1:condition}${1/(.+)/ /}{
}
endsnippet
snippet fori "Integer for loop" b
for ${1:i} := 0; $1 < ${2:N}; $1++ {
${0:${VISUAL}}
}
endsnippet
snippet forr "For range loop" b
for ${2:name} := range ${1:collection} {
${0:${VISUAL}}

View File

@ -29,4 +29,9 @@ ${1:SubSubsection}:`!p snip.rv = sec_title(snip, t)`
$0
endsnippet
# For vim help, follow the same settings as the official docs.
snippet modeline "Vim help modeline"
`!v 'vim'`:tw=78:ts=8:ft=help:norl:
endsnippet
# vim:ft=snippets:

View File

@ -194,7 +194,7 @@ endsnippet
snippet head "XHTML <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>
$0
</head>
@ -253,6 +253,10 @@ snippet td "table cell" w
<td>$0</td>
endsnippet
snippet th "table header" w
<th>$0</th>
endsnippet
snippet tr "table row" w
<tr>$0</tr>
endsnippet

View File

@ -25,8 +25,13 @@ def getArgs(group):
return [i.split(" ") for i in word.findall(group) ]
def camel(word):
if not word: return ''
return word[0].upper() + word[1:]
def mixedCase(word):
if not word: return ''
return word[0].lower() + word[1:]
endglobal
snippet sleep "try sleep catch" b
@ -55,7 +60,7 @@ abstract $0
endsnippet
snippet as "assert" b
assert ${1:test}${2/(.+)/(?1: \: ")/}${2:Failure message}${2/(.+)/(?1:")/};$0
assert ${1:test}${2/(.+)/(?1: \: ")/}${2:Failure message}${2/(.+)/(?1:")/};
endsnippet
snippet at "assert true" b
@ -63,7 +68,7 @@ assertTrue(${1:actual});
endsnippet
snippet af "assert false" b
assertFalse(${1:actual});$0
assertFalse(${1:actual});
endsnippet
snippet ae "assert equals" b
@ -136,7 +141,7 @@ if len(args) > 0:
public `!p snip.rv = snip.basename or "unknown"`($1) { `!p
args = getArgs(t[1])
for i in args:
snip.rv += "\n\t\tthis." + i[1] + " = " + i[1]
snip.rv += "\n\t\tthis.%s = %s;" % (i[1], i[1])
if len(args) == 0:
snip.rv += "\n"`
}
@ -173,15 +178,15 @@ default:
$0
endsnippet
snippet elif "else if" b
snippet elif "else if"
else if ($1)`!p nl(snip)`{
$0
$0${VISUAL}
}
endsnippet
snippet /el(se)?/ "else" br
snippet el "else" w
else`!p nl(snip)`{
$0
$0${VISUAL}
}
endsnippet
@ -209,7 +214,7 @@ endsnippet
snippet if "if" b
if ($1)`!p nl(snip)`{
$0
$0${VISUAL}
}
endsnippet
@ -219,7 +224,7 @@ $0
endsnippet
snippet im "import" b
import ${1:java}.${2:util}.$0
import ${1:java}.${2:util}.$0;
endsnippet
snippet in "interface" b
@ -264,7 +269,7 @@ if len(args) > 0:
public `!p snip.rv = snip.basename or "unknown"`($1) { `!p
args = getArgs(t[1])
for i in args:
snip.rv += "\n\t\tthis." + i[1] + " = " + i[1]
snip.rv += "\n\t\tthis.%s = %s;" % (i[1], i[1])
if len(args) == 0:
snip.rv += "\n"`
}
@ -298,7 +303,7 @@ endsnippet
snippet try "try/catch" b
try {
$1
$1${VISUAL}
} catch(${2:Exception} ${3:e}){
${4:e.printStackTrace();}
}
@ -338,23 +343,23 @@ endsnippet
snippet /get(ter)?/ "getter" br
public ${1:String} get${2:Name}() {
return `!p snip.rv = t[2].lower()`;
return `!p snip.rv = mixedCase(t[2])`;
}
endsnippet
snippet /set(ter)?/ "setter" br
public void set${1:Name}(${2:String} $1) {
return this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`;
public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) {
this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`;
}
endsnippet
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()`) {
this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`;
public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) {
this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`;
}
public $2 get$1() {
return `!p snip.rv = t[1].lower()`;
return `!p snip.rv = mixedCase(t[1])`;
}
endsnippet

View File

@ -79,6 +79,14 @@ setTimeout(function() {
}${2:.bind(${3:this})}, ${1:10});
endsnippet
snippet fi "for prop in obj using hasOwnProperty" b
for (${1:prop} in ${2:obj}){
if ($2.hasOwnProperty($1)) {
${VISUAL}$0
}
}
endsnippet
# Snippets for Console Debug Output
snippet ca "console.assert" b
@ -121,6 +129,10 @@ snippet cl "console.log" b
console.log(${1:"${2:value}"});
endsnippet
snippet cd "console.debug" b
console.debug(${1:"${2:value}"});
endsnippet
snippet cprof "console.profile" b
console.profile("${1:label}");
${VISUAL}$0

View File

@ -50,6 +50,10 @@ snippet ee "expect to equal (js)" b
expect(${1:target}).toEqual(${2:value});
endsnippet
snippet eb "expect to be (js)" b
expect(${1:target}).toBe(${2:value});
endsnippet
snippet em "expect to match (js)" b
expect(${1:target}).toMatch(${2:pattern});
endsnippet

View File

@ -2,7 +2,6 @@ priority -50
snippet t "Transaction" b
${1:`!v strftime("%Y")`}-${2:`!v strftime("%m")`}-${3:`!v strftime("%d")`} ${4:*} ${5:Payee}
${6:Expenses} \$${7:0.00}
${8:Assets:Checking}
$0
${6:Expenses} \$${7:0.00}
${8:Assets:Checking}$0
endsnippet

View File

@ -39,4 +39,15 @@ snippet img "Image"
![${1:pic alt}](${2:path}${3/.+/ "/}${3:opt title}${3/.+/"/})$0
endsnippet
snippet ilc "Inline Code" i
\`$1\`$0
endsnippet
snippet cbl "Codeblock" b
\`\`\`
$1
\`\`\`
$0
endsnippet
# vim:ft=snippets:

View File

@ -129,4 +129,11 @@ while ($1) {
endsnippet
snippet until "until"
until ($1) {
${2:# body...}
}
endsnippet
# vim:ft=snippets:

View File

@ -14,7 +14,7 @@ endsnippet
snippet do "do"
do {
${2:// code... }
} while (${1:/* condition */});"
} while (${1:/* condition */});
endsnippet
snippet doc_f "doc_f"
@ -67,6 +67,12 @@ if (${1:/* condition */}) {
}
endsnippet
snippet elif "elseif"
elseif (${1:/* condition */}) {
${2:// code...}
}
endsnippet
snippet inc "inc"
include '${1:file}';${2}
endsnippet
@ -120,19 +126,19 @@ endsnippet
snippet gs "PHP Class Getter Setter" b
/*
* Getter for ${1/(\w+)\s*;/$1/}
* Getter for $1
*/
public function get${1/(\w+)\s*;/\u$1/}()
public function get${1/\w+\s*/\u$0/}()
{
return $this->${1/(\w+)\s*;/$1/};$2
return $this->$1;$2
}
/*
* Setter for ${1/(\w+)\s*;/$1/}
* Setter for $1
*/
public function set${1/(\w+)\s*;/\u$1/}($${1/(\w+)\s*;/$1/})
public function set${1/\w+\s*/\u$0/}($$1)
{
$this->${1/(\w+)\s*;/$1/} = $${1/(\w+)\s*;/$1/};$3
$this->$1 = $$1;$3
${4:return $this;}
}
$0
@ -224,7 +230,7 @@ class $1
{
public function ${3:__construct}(${4:$options})
{
${4:// code}
${5:// code}
}
}
$0
@ -240,8 +246,8 @@ public function __construct(${1:$dependencies})
$0
endsnippet
snippet pr "Dumb debug helper in HTML"
echo '<pre>' . var_export($1, 1) . '</pre>';$0
snippet ve "Dumb debug helper in HTML"
echo '<pre>' . var_export($1, 1) . '</pre>';$0
endsnippet
snippet pc "Dumb debug helper in cli"

View File

@ -3,6 +3,28 @@
priority -50
snippet classn "Basic class with namespace snippet" b
namespace `!p
abspath = os.path.abspath(path)
m = re.search(r'[A-Z].+(?=/)', abspath)
if m:
snip.rv = m.group().replace('/', '\\')
`;
/**
* ${1:@author `whoami`}
*/
class `!p
snip.rv = re.match(r'.*(?=\.)', fn).group()
`$2
{
public function __construct(${3:$options})
{
${4:// code}
}$0
}
endsnippet
snippet contr "Symfony2 controller" b
namespace `!p
abspath = os.path.abspath(path)

View File

@ -34,13 +34,30 @@ global !p
NORMAL = 0x1
DOXYGEN = 0x2
SPHINX = 0x3
GOOGLE = 0x4
SINGLE_QUOTES = 0x1
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):
args = [arg.split('=')[0].strip() for arg in arglist.split(',') if arg]
args = [arg for arg in args if arg and arg != "self"]
args = [Arg(arg) for arg in arglist.split(',') if arg]
args = [arg for arg in args if arg.name != 'self']
return args
@ -51,7 +68,7 @@ def get_quoting_style(snip):
return SINGLE_QUOTES
return DOUBLE_QUOTES
def tripple_quotes(snip):
def triple_quotes(snip):
if get_quoting_style(snip) == SINGLE_QUOTES:
return "'''"
return '"""'
@ -61,36 +78,65 @@ def get_style(snip):
if style == "doxygen": return DOXYGEN
elif style == "sphinx": return SPHINX
elif style == "google": return GOOGLE
else: return NORMAL
def format_arg(arg, style):
if style == DOXYGEN:
return "@param %s @todo" % arg
return "@param %s TODO" % arg
elif style == SPHINX:
return ":param %s: @todo" % arg
return ":param %s: TODO" % arg
elif style == NORMAL:
return ":%s: @todo" % arg
return ":%s: TODO" % arg
elif style == GOOGLE:
return "%s (TODO): TODO" % arg
def format_return(style):
if style == DOXYGEN:
return "@return: @todo"
return "@return: TODO"
elif style in (NORMAL, SPHINX):
return ":returns: @todo"
return ":returns: TODO"
elif style == GOOGLE:
return "Returns: TODO"
def write_docstring_args(args, snip):
if not args:
snip.rv += ' {0}'.format(tripple_quotes(snip))
snip.rv += ' {0}'.format(triple_quotes(snip))
return
snip.rv += '\n' + snip.mkline('', indent='')
style = get_style(snip)
for arg in args:
snip += format_arg(arg, style)
if style == GOOGLE:
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):
@ -120,10 +166,10 @@ endglobal
snippet class "class with docstrings" b
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):
`!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 >> 2
@ -132,7 +178,7 @@ args = get_args(t[4])
write_docstring_args(args, snip)
if args:
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)
`
@ -143,7 +189,7 @@ endsnippet
snippet slotclass "class with slots and docstrings" b
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
snip >> 1
args = get_args(t[4])
@ -151,7 +197,7 @@ write_slots_args(args, snip)
`
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 >> 2
@ -160,7 +206,7 @@ args = get_args(t[4])
write_docstring_args(args, snip)
if args:
snip.rv += '\n' + snip.mkline('', indent='')
snip += tripple_quotes(snip)
snip += triple_quotes(snip)
write_init_body(args, t[2], snip)
`
@ -353,7 +399,7 @@ snippet def "function with docstrings" b
def ${1:function}(`!p
if snip.indent:
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 >> 1
@ -364,7 +410,7 @@ if args:
style = get_style(snip)
snip += format_return(style)
snip.rv += '\n' + snip.mkline('', indent='')
snip += tripple_quotes(snip) `
snip += triple_quotes(snip) `
${0:pass}
endsnippet
@ -390,8 +436,8 @@ endsnippet
snippet rwprop "Read write property" b
def ${1:name}():
`!p snip.rv = tripple_quotes(snip) if t[2] else ''
`${2:@todo: Docstring for $1.}`!p
`!p snip.rv = triple_quotes(snip) if t[2] else ''
`${2:TODO: Docstring for $1.}`!p
if t[2]:
snip >> 1
@ -399,7 +445,7 @@ if t[2]:
snip.rv += '\n' + snip.mkline('', indent='')
snip += format_return(style)
snip.rv += '\n' + snip.mkline('', indent='')
snip += tripple_quotes(snip)
snip += triple_quotes(snip)
else:
snip.rv = ""`
def fget(self):
@ -514,11 +560,18 @@ snippet ar "Assert raises" b
self.assertRaises(${1:exception}, ${2:func}${3/.+/, /}${3:arguments})
endsnippet
snippet an "Assert is None" b
self.assertIsNone(${0:expression})
endsnippet
snippet ann "Assert is not None" b
self.assertIsNotNone(${0:expression})
endsnippet
snippet testcase "pyunit testcase" b
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):
${4:pass}

View File

@ -12,6 +12,8 @@ from string import Template
import re
from collections import Counter
from vimsnippets import complete
#http://docutils.sourceforge.net/docs/ref/rst/roles.html
TEXT_ROLES = ['emphasis','literal','code','math',
'pep-reference','rfc-reference',
@ -40,18 +42,9 @@ INCLUDABLE_DIRECTIVES = ['image', 'figure', 'include']
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
def has_cjk(char):
"""
Detect char contains CJK character
:param char: characters needs to be detect
"""
try:
CJK_RE.finditer(char).next()
except StopIteration:
return False
else:
return True
def has_cjk(s):
"""Detect if s contains CJK characters."""
return CJK_RE.search(s) is not None
def real_filename(filename):
"""pealeextension name off if possible
@ -72,15 +65,17 @@ def check_file_exist(rst_path, relative_path):
return abs_path
def rst_char_len(char):
"""
return len of string which fit in rst
For instance:chinese "我" decode as only one character,
However, the rst interpreter needs 2 "=" instead of 1.
try:
rst_char_len = vim.strwidth # Requires Vim 7.3+
except AttributeError:
from unicodedata import east_asian_width
def rst_char_len(s):
"""Return the required over-/underline length for s."""
result = 0
for c in s:
result += 2 if east_asian_width(c) in ('W', 'F') else 1
return result
:param: char needs to be count
"""
return len(re.findall(r'[^\u4e00-\u9fff\s]', char))+len(char)
def make_items(times, leading='+'):
"""
@ -92,7 +87,7 @@ def make_items(times, leading='+'):
times = int(times)
if leading == 1:
msg = ""
for x in xrange(1, times+1):
for x in range(1, times+1):
msg += "%s. Item\n" % x
return msg
else:
@ -130,68 +125,47 @@ def get_popular_code_type():
except IndexError:
popular_type = "lua" # Don't break default
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
snippet part "Part" b
`!p snip.rv = rst_char_len(t[1])*'#'`
${1:Part name}
${1:${VISUAL:Part name}}
`!p snip.rv = rst_char_len(t[1])*'#'`
$0
endsnippet
snippet sec "Section" b
${1:Section name}
`!p snip.rv = rst_char_len(t[1])*'='`
$0
endsnippet
snippet ssec "Subsection" b
${1:Section name}
`!p snip.rv = rst_char_len(t[1])*'-'`
$0
endsnippet
snippet sssec "Subsubsection" b
${1:Section name}
`!p snip.rv = rst_char_len(t[1])*'^'`
$0
endsnippet
snippet chap "Chapter" b
`!p snip.rv = rst_char_len(t[1])*'*'`
${1:Chapter name}
${1:${VISUAL:Chapter name}}
`!p snip.rv = rst_char_len(t[1])*'*'`
$0
endsnippet
snippet sec "Section" b
${1:${VISUAL:Section name}}
`!p snip.rv = rst_char_len(t[1])*'='`
$0
endsnippet
snippet ssec "Subsection" b
${1:${VISUAL:Subsection name}}
`!p snip.rv = rst_char_len(t[1])*'-'`
$0
endsnippet
snippet sssec "Subsubsection" b
${1:${VISUAL:Subsubsection name}}
`!p snip.rv = rst_char_len(t[1])*'^'`
$0
endsnippet
snippet para "Paragraph" b
${1:Paragraph name}
${1:${VISUAL:Paragraph name}}
`!p snip.rv = rst_char_len(t[1])*'"'`
$0
@ -199,7 +173,7 @@ endsnippet
snippet em "Emphasize string" i
`!p
# dirty but works with CJK charactor detection
# dirty but works with CJK character detection
if has_cjk(vim.current.line):
snip.rv ="\ "`*${1:${VISUAL:Em}}*`!p
if has_cjk(vim.current.line):
@ -243,7 +217,7 @@ endsnippet
snippet cb "Code Block" b
.. code-block:: ${1:`!p snip.rv = get_popular_code_type()`}
${2:code}
${2:${VISUAL:code}}
$0
endsnippet
@ -266,7 +240,10 @@ if di == 'fi':
:alt: {0}
{0}""".format(real_name)
`
..`!p snip.rv = " %s" % link if link else ""` $1`!p snip.rv=complete(t[1], INCLUDABLE_DIRECTIVES)`:: ${2:file}`!p if content:
..`!p snip.rv = " %s" % link if link else ""` $1`!p
snip.rv=complete(t[1], INCLUDABLE_DIRECTIVES)
`:: ${2:${VISUAL:file}}`!p
if content:
snip.rv +=" "+content`
`!p
# Tip of whether file is exist in comment type
@ -280,7 +257,7 @@ endsnippet
snippet di "Directives" b
.. $1`!p snip.rv=complete(t[1], DIRECTIVES)`:: $2
${3:Content}
${3:${VISUAL:Content}}
$0
endsnippet
@ -292,7 +269,7 @@ endsnippet
snippet sa "Specific Admonitions" b
.. $1`!p snip.rv =complete(t[1], SPECIFIC_ADMONITIONS)`::
${2:Content}
${2:${VISUAL:Content}}
$0
endsnippet
@ -311,6 +288,6 @@ endsnippet
snippet sid "SideBar" b
.. sidebar:: ${1:SideBar Title}
${2:SideBar Content}
${2:${VISUAL:SideBar Content}}
endsnippet
# vim:ft=snippets:

View File

@ -1,54 +1,56 @@
extends css
priority -50
snippet /@?imp/ "@import '...';" br
snippet imp "@import '...';" b
@import '${1:file}';
endsnippet
snippet /@?inc/ "@include mixin(...);" br
snippet inc "@include mixin(...);" b
@include ${1:mixin}(${2:arguments});
endsnippet
snippet /@?ext?/ "@extend %placeholder;" br
snippet ext "@extend %placeholder;" b
@extend %${1:placeholder};
endsnippet
snippet /@?mixin/ "@mixin (...) { ... }" br
snippet mixin "@mixin (...) { ... }" b
@mixin ${1:name}(${2:arguments}) {
${VISUAL}$0
}
endsnippet
snippet /@?fun/ "@function (...) { ... }" br
snippet fun "@function (...) { ... }" b
@function ${1:name}(${2:arguments}) {
${VISUAL}$0
}
endsnippet
snippet /@?if/ "@if (...) { ... }" br
snippet if "@if (...) { ... }" b
@if ${1:condition} {
${VISUAL}$0
}
endsnippet
snippet /(} )?@?else/ "@else { ... }" br
snippet else "@else { ... }" b
@else ${1:condition} {
${VISUAL}$0
}
endsnippet
snippet /@?for/ "@for loop" br
snippet for "@for loop" b
@for ${1:$i} from ${2:1} through ${3:3} {
${VISUAL}$0
}
endsnippet
snippet /@?each/ "@each loop" br
snippet each "@each loop" b
@each ${1:$item} in ${2:item, item, item} {
${VISUAL}$0
}
endsnippet
snippet /@?while/ "@while loop" br
snippet while "@while loop" b
@while ${1:$i} ${2:>} ${3:0} {
${VISUAL}$0
}

View File

@ -8,7 +8,7 @@ snippet "b(egin)?" "begin{} / end{}" br
\end{$1}
endsnippet
snippet tab
snippet tab "tabular / array environment" b
\begin{${1:t}${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}}{${2:c}}
$0${2/((?<=.)c|l|r)|./(?1: & )/g}
\end{$1${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}}

View File

@ -3,58 +3,22 @@ priority -50
###########################################################################
# SnipMate Snippets #
###########################################################################
snippet header
" File: ${1:`!v expand('%:t')`}
" Author: ${2:`!v g:snips_author`}
" Description: ${3}
${4:" Last Modified: `!v strftime("%B %d, %Y")`}
$0
endsnippet
snippet gvar "Global / configuration variable"
snippet gvar "Global / configuration variable" b
if !exists("g:${1:MyUltraImportantVar}")
let g:$1 = ${2:"${3:<tab>}"}
endif
endsnippet
snippet guard
snippet guard "script reload guard" b
if exists('${1:did_`!p snip.rv = snip.fn.replace('.','_')`}') || &cp${2: || version < 700}
finish
endif
let $1 = 1${3}
endsnippet
snippet f
snippet f "function" b
fun ${1:function_name}(${2})
${3:" code}
endf
endsnippet
snippet for
for ${1:needle} in ${2:haystack}
${3:" code}
endfor
endsnippet
snippet wh
while ${1:condition}
${2:" code}
endw
endsnippet
snippet if
if ${1:condition}
${2:" code}
endif
endsnippet
snippet ife
if ${1:condition}
${2}
else
${3}
endif
endsnippet
# vim:ft=snippets: