Updated snippets to use new "snip" object.

This commit is contained in:
rygwdn@gmail.com 2010-07-30 21:29:40 -03:00
parent e6759cd03f
commit f88076636e
11 changed files with 81 additions and 103 deletions

View File

@ -10,14 +10,15 @@ c = '#'
cs = vim.eval("&commentstring")
if len(cs) == 3:
c = cs[0]
snip.locals["c"] = c
res = (len(t[1])+4)*c + '\n' + c + ' '`${1:content}`!p
c = '#'
cs = vim.eval("&commentstring")
if len(cs) == 3:
c = cs[0]
snip.rv = (len(t[1])+4)*c
snip.locals["bar"] = snip.rv
snip += c + ' '`${1:content}`!p
c = snip.locals["c"]
res = ' ' + c + '\n' + (len(t[1])+4)*c`
snip.rv = ' ' + c
snip += snip.locals["bar"]`
$0
endsnippet
@ -27,15 +28,17 @@ c = '#'
cs = vim.eval("&commentstring")
if len(cs) == 3:
c = cs[0]
snip.locals["c"] = c
snip.locals["bar"] = 75*c
res = 75*c + '\n' + c + " "+ (71-len(t[1]))/2*' '
snip.rv = snip.locals["bar"]
snip += c + " " + (71-len(t[1]))/2*' '
`${1:content}`!p
c = '#'
cs = vim.eval("&commentstring")
if len(cs) == 3:
c = cs[0]
c = snip.locals["c"]
a = 71-len(t[1]); res = (a/2 + a%2) * " " + " " + c + '\n' + 75*c`
a = 71-len(t[1])
snip.rv = (a/2 + a%2) * " " + " " + c
snip += snip.locals["bar"]`
$0
endsnippet

View File

@ -9,7 +9,7 @@ snippet def "#ifndef … #define … #endif"
endsnippet
snippet inc "#include "" (inc)"
#include "${1:`!p res=fn.split('.')[-2]+'.h'`}"
#include "${1:`!p snip.rv = snip.basename + '.h'`}"
endsnippet
snippet Inc "#include <> (Inc)"
@ -46,11 +46,11 @@ endsnippet
snippet once "Include header once only guard"
#ifndef ${1:`!p
if not len(cur):
if not len(snip.c):
import random, string
name = re.sub(r'[^A-Za-z0-9]+','_', fn).upper()
name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper()
rand = ''.join(random.sample(string.ascii_letters+string.digits, 8))
res = ('%s_%s' % (name,rand)).upper()`}
snip.rv = ('%s_%s' % (name,rand)).upper()`}
#define $1
${0}
@ -85,8 +85,7 @@ printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2
endsnippet
snippet st "struct"
struct ${1:`!p if fn != "": res = fn.split(".")[-2].lower()+"_t"
else: res = "name"`}
struct ${1:`!p snip.rv = (snip.basename or "name") + "_t"`}
{
${0:/* data */}
};

View File

@ -8,11 +8,7 @@ ${1:v}${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}begin(), $1${1/^.*?(-)?(>)?$/(?2::(?1:>:
endsnippet
snippet cl "class .. (class)"
class ${1:`!p
if len(fn):
res = fn.split(".")[-2].lower()+ '_t'
else:
res = "name"`}
class ${1:`!p snip.rv = snip.basename or "name"`}
{
public:
${1/(\w+).*/$1/} (${2:arguments});
@ -24,9 +20,7 @@ private:
endsnippet
snippet ns "namespace .. (namespace)"
namespace${1/.+/ /m}${1:`!p
if len(fn): res = fn.split(".")[-2].lower()
else: res ="name"`}
namespace${1/.+/ /m}${1:`!p snip.rv = snip.basename or "name"`}
{
$0
}${1/.+/ \/* /m}$1${1/.+/ *\/ /m}

View File

@ -3,21 +3,22 @@
snippet sec "Section marker" b
=============================================================================
${1:SECTION}`!p
file_start = fn.split('.')[0]
file_start = snip.fn.split('.')[0]
sec_name = t[1].strip("1234567890. ").lower().replace(' ', '-')
res = ("*%s-%s*" % (file_start, sec_name)).rjust(77-len(t[1]))`
snip.rv = ("*%s-%s*" % (file_start, sec_name)).rjust(77-len(t[1]))`
$0
endsnippet
snippet ssec "Sub section marker" b
${1:Subsection}`!p
file_start = fn.split('.')[0]
file_start = snip.fn.split('.')[0]
sec_name = t[1].strip("1234567890. ").lower().replace(' ', '-')
sec_title = ("*%s-%s*" % (file_start, sec_name)).rjust(77-len(t[1]))
res = sec_title + "\n" + "-"*len(t[1])`
snip.rv = sec_title
snip += "-"*len(t[1])`
$0
endsnippet
@ -28,7 +29,7 @@ file_start = fn.split('.')[0]
sec_name = t[1].strip("1234567890. ").lower().replace(' ', '-')
sec_title = ("*%s-%s*" % (file_start, sec_name)).rjust(77-len(t[1]))
res = sec_title`
snip.rv = sec_title`
$0
endsnippet

View File

@ -112,12 +112,12 @@ endsnippet
# HTML TAGS #
#############
snippet input "Input with Label"
<label for="${2:${1/[[:alpha:]]+|( )/(?1:_:\L$0)/g}}">$1</label><input type="${3:text/submit/hidden/button}" name="${4:$2}" value="$5"${6: id="${7:$2}"}`!p if vim.eval("&filetype").startswith("x"): res = '/'`>
<label for="${2:${1/[[:alpha:]]+|( )/(?1:_:\L$0)/g}}">$1</label><input type="${3:text/submit/hidden/button}" name="${4:$2}" value="$5"${6: id="${7:$2}"}`!p if snip.ft.startswith("x"): snip.rv = '/'`>
endsnippet
snippet input "XHTML <input>"
<input type="${1:text/submit/hidden/button}" name="${2:some_name}" value="$3"${4: id="${5:$2}"}`!p if vim.eval("&filetype").startswith("x"): res = '/'`>
<input type="${1:text/submit/hidden/button}" name="${2:some_name}" value="$3"${4: id="${5:$2}"}`!p if snip.ft.startswith("x"): snip.rv = '/'`>
endsnippet
@ -143,15 +143,12 @@ snippet mailto "XHTML <a mailto: >"
endsnippet
snippet base "XHTML <base>"
<base href="$1"${2: target="$3"}`!p if vim.eval("&filetype").startswith("x"): res = '/'`>
<base href="$1"${2: target="$3"}`!p if snip.ft.startswith("x"): snip.rv = '/'`>
endsnippet
snippet body "XHTML <body>"
<body id="${1:`!p
if len(fn):
res = "Hallo"
else:
res = "Nothin"
snip.rv = snip.fn and 'Hallo' or 'Nothin'
`}"${2: onload="$3"}>
$0
</body>
@ -164,14 +161,12 @@ snippet div "XHTML <div>"
endsnippet
snippet form "XHTML <form>"
<form action="${1:`!p if len(fn):
res = fn.split('.')[-2]
else:
res = "unnamed"
res += '_submit'`}" method="${2:get}" accept-charset="utf-8">
<form action="${1:`!p
snip.rv = (snip.basename or 'unnamed') + '_submit'
`}" method="${2:get}" accept-charset="utf-8">
$0
<p><input type="submit" value="Continue →"`!p if vim.eval("&filetype").startswith("x"): res = '/'`></p>
<p><input type="submit" value="Continue →"`!p if snip.ft.startswith("x"): snip.rv = '/'`></p>
</form>
endsnippet
@ -181,21 +176,18 @@ endsnippet
snippet head "XHTML <head>"
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"`!p if vim.eval("&filetype").startswith("x"): res = '/'`>
<title>${1:`!p if len(fn):
res = fn.split('.')[-2]
else:
res = "Page Title"`}</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"`!p if snip.ft.startswith("x"): snip.rv = '/'`>
<title>${1:`!p snip.rv = snip.basename or "Page Title"`}</title>
$0
</head>
endsnippet
snippet link "XHTML <link>"
<link rel="${1:stylesheet}" href="${2:/css/master.css}" type="text/css" media="${3:screen}" title="${4:no title}" charset="${5:utf-8}"`!p if vim.eval("&filetype").startswith("x"): res = '/'`>
<link rel="${1:stylesheet}" href="${2:/css/master.css}" type="text/css" media="${3:screen}" title="${4:no title}" charset="${5:utf-8}"`!p if snip.ft.startswith("x"): snip.rv = '/'`>
endsnippet
snippet meta "XHTML <meta>"
<meta name="${1:name}" content="${2:content}"`!p if vim.eval("&filetype").startswith("x"): res = '/'`>
<meta name="${1:name}" content="${2:content}"`!p if snip.ft.startswith("x"): snip.rv = '/'`>
endsnippet
snippet scriptsrc "XHTML <script src...>"
@ -222,10 +214,7 @@ snippet table "XHTML <table>"
endsnippet
snippet title "XHTML <title>"
<title>${1:`!p if len(fn):
res = fn.split('.')[-2]
else:
res = "Page Title"`}</title>
<title>${1:`!p snip.rv = snip.basename or "Page Title"`}</title>
endsnippet
snippet fieldset "Fieldset"
@ -238,15 +227,15 @@ endsnippet
snippet movie "Embed QT movie (movie)" b
<object width="$2" height="$3" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="$1"`!p snip['xhtml'] = vim.eval("&filetype").startswith("x") and "/" or ""; res = snip['xhtml']`>
<param name="controller" value="$4"`!p res = snip['xhtml']`>
<param name="autoplay" value="$5"`!p res = snip['xhtml']`>
<param name="src" value="$1"`!p snip.locals['xhtml'] = snip.ft.startswith("x") and "/" or ""; snip.rv = snip.locals['xhtml']`>
<param name="controller" value="$4"`!p snip.rv = snip.locals['xhtml']`>
<param name="autoplay" value="$5"`!p snip.rv = snip.locals['xhtml']`>
<embed src="${1:movie.mov}"
width="${2:320}" height="${3:240}"
controller="${4:true}" autoplay="${5:true}"
scale="tofit" cache="true"
pluginspage="http://www.apple.com/quicktime/download/"
`!p res = snip['xhtml']`>
`!p snip.rv = snip.locals['xhtml']`>
</object>
endsnippet

View File

@ -27,10 +27,8 @@ catch (${1:Exception} ${2:e}) {
endsnippet
snippet cl "class" b
class ${1:`!p if len(fn):
res = fn.split('.')[-2]
else:
res = "untitled"`} ${2:extends ${3:Parent} }${4:implements ${5:Interface} }{
class ${1:`!p
snip.rv = snip.basename or "untitled"`} ${2:extends ${3:Parent} }${4:implements ${5:Interface} }{
$0
}
endsnippet
@ -92,10 +90,7 @@ import
endsnippet
snippet in "interface" b
interface ${1:`!p if len(fn):
res = fn.split('.')[-2]
else:
res = "untitled"`} ${2:extends ${3:Parent} }{
interface ${1:`!p snip.rv = snip.basename or "untitled"`} ${2:extends ${3:Parent} }{
$0
}
endsnippet
@ -176,10 +171,7 @@ synchronized
endsnippet
snippet tc "test case"
public class ${1:`!p if len(fn):
res = fn.split('.')[-2]
else:
res = "untitled"`} extends ${2:TestCase} {
public class ${1:`!p snip.rv = snip.basename or "untitled"`} extends ${2:TestCase} {
$0
}
endsnippet

View File

@ -24,52 +24,52 @@ class ${1:MyClass}(${2:object}):
def __init__(self$4):
""" ${5:TODO: Fill me in}`!p
res = ""
snip.reset_indent()
snip.shift(2)
snip.rv = ""
snip >> 2
args = [arg.split('=')[0].strip() for arg in t[4].split(',') if arg]
args = [arg for arg in args if arg and arg != "self"]
if args:
res += snip.mkline('\n')
snip += ""
for arg in args:
res += snip.mkline(":%s: description" % arg)
snip += ":%s: description" % arg
if args:
res += snip.mkline('"""')
snip += '"""'
else:
res += snip.mkline(' """', '')
snip.rv += ' """'
if t[2] != "object":
res += snip.mkline(t[2] + ".__init__(self)\n")
for sup in t[2].split(","):
sup = sup.strip()
snip += sup + ".__init__(self)"
for arg in args:
res += snip.mkline("self._%s = %s" % (arg, arg))
snip += "self._%s = %s" % (arg, arg)
`
$0
endsnippet
snippet def "smart def" b
def ${1:function}(${2:self}):
""" ${3:TODO: Docstring for $1}
`!p res = ""
snip.reset_indent()
""" ${3:TODO: Docstring for $1}`!p
snip.rv = ""
snip >> 1
args = [arg.split('=')[0].strip() for arg in t[2].split(',') if arg.strip()]
args = [arg.split('=')[0].strip() for arg in t[2].split(',') if arg]
args = [arg for arg in args if arg and arg != "self"]
if args:
res += snip.mkline()
snip += ""
snip.shift()
for arg in args:
res += snip.mkline(":%s: description" % arg)
snip += ":%s: description" % arg
`
:returns: description
"""
`${4:
:returns: ${5:description}
}"""
${0:pass}
endsnippet

View File

@ -1,30 +1,30 @@
snippet part "Part" b
`!p res=len(t[1])*'*'`
`!p snip.rv = len(t[1])*'*'`
${1:Part name}
`!p res=len(t[1])*'*'`
`!p snip.rv = len(t[1])*'*'`
$0
endsnippet
snippet sec "Section" b
${1:Section name}
`!p res=len(t[1])*'='`
`!p snip.rv = len(t[1])*'='`
$0
endsnippet
snippet ssec "Subsection" b
${1:Section name}
`!p res=len(t[1])*'-'`
`!p snip.rv = len(t[1])*'-'`
$0
endsnippet
snippet sssec "Subsubsection" b
${1:Section name}
`!p res=len(t[1])*'^'`
`!p snip.rv = len(t[1])*'^'`
$0
endsnippet

View File

@ -13,9 +13,9 @@ snippet !env "#!/usr/bin/env (!env)"
endsnippet
snippet temp "Tempfile"
${1:TMPFILE}="$(mktemp -t ${2:`!p res = re.sub(r'[^a-zA-Z]', '_', fn)
if not len(res):
res = "untitled"`})"
${1:TMPFILE}="$(mktemp -t ${2:`!p
snip.rv = re.sub(r'[^a-zA-Z]', '_', snip.fn) or "untitled"
`})"
${3:${4/(.+)/trap "/}${4:rm -f '$${1/.*\s//}'}${4/(.+)/" 0 # EXIT\n/}${5/(.+)/trap "/}${5:rm -f '$${1/.*\s//}'; exit 1}${5/(.+)/" 2 # INT\n/}${6/(.+)/trap "/}${6:rm -f '$${1/.*\s//}'; exit 1}${6/(.+)/" 1 15 # HUP TERM\n/}}
endsnippet

View File

@ -5,8 +5,8 @@
# We use a little hack so that the snippet is expanded
# and parsed correctly
snippet snip "Snippet definition" !
`!p res="snippet"` ${1:Tab_trigger} "${2:Description}" ${3:!b}
`!p snip.rv = "snippet"` ${1:Tab_trigger} "${2:Description}" ${3:!b}
$0
`!p res="endsnippet"`
`!p snip.rv = "endsnippet"`
endsnippet

View File

@ -17,7 +17,7 @@ endif
endsnippet
snippet guard
if exists('${1:did_`!p res=fn.replace('.','_')`}') || &cp${2: || version < 700}
if exists('${1:did_`!p snip.rv = snip.fn.replace('.','_')`}') || &cp${2: || version < 700}
finish
endif
let $1 = 1${3}