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 snippet class "smart class" b
class ${1:MyClass}(${2:object}): class ${1:MyClass}(${2:object}):
"""${3:Docstring for $1}""" """ ${3:Docstring for $1} """
def __init__( self${4/([^,])?(.*)/(?1:, )/}${4:arg} ): def __init__(self$4):
""" """ ${5:TODO: Fill me in}
TODO: Fill me in `!p res = ""
${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} """ ts = '\t'
${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} 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 endsnippet
snippet def "smart def" b snippet def "smart def" b
def ${1:function}(${2/([^,])?(.*)/(?1:)/}${2:arg}): def ${1:function}(${2:self}):
"""${3:Docstring for $1} """ ${3:TODO: 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} `!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 :returns: description
""" """
${0:pass} ${0:pass}