added new 'smart def' and 'smart class' for python using new indent info

This commit is contained in:
rygwdn@gmail.com 2010-05-16 02:08:46 -03:00
parent 741686603a
commit 8f7cdb9c69

View File

@ -20,19 +20,54 @@ endsnippet
##########
snippet class "smart class" b
class ${1:MyClass}(${2:object}):
"""${3:Docstring for $1}"""
""" ${3:Docstring for $1} """
def __init__( self${4/([^,])?(.*)/(?1:, )/}${4:arg} ):
"""
TODO: Fill me in
${4/.+/(?0:\n)/}${4/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=[^,]*)?(,\s*|$)/(?2: $2 - describe me here\n)/g} """
${2/object$|(.+)/(?1: $0.__init__\(self\)\n\n)/}${4/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=[^,]*)?(,\s*|$)/(?2: self._$2 = $2\n)/g}
def __init__(self$4):
""" ${5:TODO: Fill me in}
`!p res = ""
ts = '\t'
if vim.eval("&expandtab") == 1:
ts = " " * int(vim.eval("&ts"))
indent = initial_indent + ts * 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 += '\n'
for i, arg in enumerate(args):
res += indent
res += ":%s: description\n" % arg
res += indent + '"""\n'
if t[2] != "object":
res += indent + t[2] + ".__init__(self)\n\n"
for i, arg in enumerate(args):
res += indent
res += "self._%s = %s\n" % (arg, arg)
`
$0
endsnippet
snippet def "smart def" b
def ${1:function}(${2/([^,])?(.*)/(?1:)/}${2:arg}):
"""${3:Docstring for $1}
${2/.+/(?0:\n)/}${2/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=[^,]*)?(,\s*|$)/ :param $2: description\n/g}
def ${1:function}(${2:self}):
""" ${3:TODO: Docstring for $1}
`!p res = ""
ts = '\t'
if vim.eval("&expandtab") == 1:
ts = " " * int(vim.eval("&ts"))
args = [arg.split('=')[0].strip() for arg in t[2].split(',') if arg.strip()]
args = [arg for arg in args if arg and arg != "self"]
if args:
res += '\n'
indent = initial_indent + ts
for arg in args:
res += indent + ":%s: description\n" % arg
`
:returns: description
"""
${0:pass}