mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 14:43:35 +08:00 
			
		
		
		
	Updated plugins. Added vim-golang as a mode
This commit is contained in:
		| @ -1,3 +1,5 @@ | ||||
| priority -50 | ||||
|  | ||||
| ########################################################################### | ||||
| #                            TEXTMATE SNIPPETS                            # | ||||
| ########################################################################### | ||||
| @ -14,6 +16,10 @@ if __name__ == '__main__': | ||||
| 	${1:main()}$0 | ||||
| endsnippet | ||||
|  | ||||
| snippet for "for loop" b | ||||
| for ${1:item} in ${2:iterable}: | ||||
| 	${3:pass} | ||||
| endsnippet | ||||
|  | ||||
| ########## | ||||
| # COMMON # | ||||
| @ -29,67 +35,81 @@ NORMAL  = 0x1 | ||||
| DOXYGEN = 0x2 | ||||
| SPHINX  = 0x3 | ||||
|  | ||||
| SINGLE_QUOTES = 0x1 | ||||
| DOUBLE_QUOTES = 0x2 | ||||
|  | ||||
| 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.split('=')[0].strip() for arg in arglist.split(',') if arg] | ||||
| 	args = [arg for arg in args if arg and arg != "self"] | ||||
|  | ||||
|     return args | ||||
| 	return args | ||||
|  | ||||
|  | ||||
| def get_quoting_style(snip): | ||||
| 	style = snip.opt("g:ultisnips_python_quoting_style", "double") | ||||
| 	if style == 'single': | ||||
| 		return SINGLE_QUOTES | ||||
| 	return DOUBLE_QUOTES | ||||
|  | ||||
| def tripple_quotes(snip): | ||||
| 	if get_quoting_style(snip) == SINGLE_QUOTES: | ||||
| 		return "'''" | ||||
| 	return '"""' | ||||
|  | ||||
| def get_style(snip): | ||||
|     style = snip.opt("g:ultisnips_python_style", "normal") | ||||
| 	style = snip.opt("g:ultisnips_python_style", "normal") | ||||
|  | ||||
|     if    style == "doxygen": return DOXYGEN | ||||
|     elif  style == "sphinx": return SPHINX | ||||
|     else: return NORMAL | ||||
| 	if    style == "doxygen": return DOXYGEN | ||||
| 	elif  style == "sphinx": return SPHINX | ||||
| 	else: return NORMAL | ||||
|  | ||||
|  | ||||
| def format_arg(arg, style): | ||||
|     if style == DOXYGEN: | ||||
|         return "@param %s @todo" % arg | ||||
|     elif style == SPHINX: | ||||
|         return ":param %s: @todo" % arg | ||||
|     elif style == NORMAL: | ||||
|         return ":%s: @todo" % arg | ||||
| 	if style == DOXYGEN: | ||||
| 		return "@param %s @todo" % arg | ||||
| 	elif style == SPHINX: | ||||
| 		return ":param %s: @todo" % arg | ||||
| 	elif style == NORMAL: | ||||
| 		return ":%s: @todo" % arg | ||||
|  | ||||
|  | ||||
| def format_return(style): | ||||
|     if style == DOXYGEN: | ||||
|         return "@return: @todo" | ||||
|     elif style in (NORMAL, SPHINX): | ||||
|         return ":returns: @todo" | ||||
| 	if style == DOXYGEN: | ||||
| 		return "@return: @todo" | ||||
| 	elif style in (NORMAL, SPHINX): | ||||
| 		return ":returns: @todo" | ||||
|  | ||||
|  | ||||
| def write_docstring_args(args, snip): | ||||
|     if not args: | ||||
|         snip.rv += ' """' | ||||
|         return | ||||
| 	if not args: | ||||
| 		snip.rv += ' {0}'.format(tripple_quotes(snip)) | ||||
| 		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: | ||||
|         snip += format_arg(arg, style) | ||||
| 	for arg in args: | ||||
| 		snip += format_arg(arg, style) | ||||
|  | ||||
|  | ||||
| def write_init_body(args, parents, snip): | ||||
|     parents = [p.strip() for p in parents.split(",")] | ||||
|     parents = [p for p in parents if p != 'object'] | ||||
| 	parents = [p.strip() for p in parents.split(",")] | ||||
| 	parents = [p for p in parents if p != 'object'] | ||||
|  | ||||
|     for p in parents: | ||||
|         snip += p + ".__init__(self)" | ||||
| 	for p in parents: | ||||
| 		snip += p + ".__init__(self)" | ||||
|  | ||||
|     if parents: | ||||
|         snip.rv += '\n' + snip.mkline('', indent='') | ||||
| 	if parents: | ||||
| 		snip.rv += '\n' + snip.mkline('', indent='') | ||||
|  | ||||
|     for arg in args: | ||||
|         snip += "self._%s = %s" % (arg, arg) | ||||
| 	for arg in args: | ||||
| 		snip += "self._%s = %s" % (arg, arg) | ||||
|  | ||||
|  | ||||
| def write_slots_args(args, snip): | ||||
|     args = ['"%s"' % arg for arg in args] | ||||
|     snip += '__slots__ = (%s,)' % ', '.join(args) | ||||
| 	args = ['"_%s"' % arg for arg in args] | ||||
| 	snip += '__slots__ = (%s,)' % ', '.join(args) | ||||
|  | ||||
| endglobal | ||||
|  | ||||
| @ -99,10 +119,11 @@ endglobal | ||||
|  | ||||
| snippet class "class with docstrings" b | ||||
| class ${1:MyClass}(${2:object}): | ||||
| 	"""${3:Docstring for $1 }""" | ||||
|  | ||||
| 	`!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)` | ||||
|  | ||||
| 	def __init__(self$4): | ||||
| 		"""${5:@todo: to be defined}`!p | ||||
| 		`!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined1.}`!p | ||||
| snip.rv = "" | ||||
| snip >> 2 | ||||
|  | ||||
| @ -110,8 +131,8 @@ args = get_args(t[4]) | ||||
|  | ||||
| write_docstring_args(args, snip) | ||||
| if args: | ||||
|     snip.rv += '\n' + snip.mkline('', indent='') | ||||
|     snip += '"""' | ||||
| 	snip.rv += '\n' + snip.mkline('', indent='') | ||||
| 	snip += '{0}'.format(tripple_quotes(snip)) | ||||
|  | ||||
| write_init_body(args, t[2], snip) | ||||
| ` | ||||
| @ -121,7 +142,8 @@ endsnippet | ||||
|  | ||||
| snippet slotclass "class with slots and docstrings" b | ||||
| class ${1:MyClass}(${2:object}): | ||||
| 	"""${3:Docstring for $1 }""" | ||||
|  | ||||
| 	`!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)` | ||||
| `!p | ||||
| snip >> 1 | ||||
| args = get_args(t[4]) | ||||
| @ -129,7 +151,7 @@ write_slots_args(args, snip) | ||||
| ` | ||||
|  | ||||
| 	def __init__(self$4): | ||||
| 		"""${5:@todo: to be defined}`!p | ||||
| 		`!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined.}`!p | ||||
| snip.rv = "" | ||||
| snip >> 2 | ||||
|  | ||||
| @ -137,8 +159,8 @@ args = get_args(t[4]) | ||||
|  | ||||
| write_docstring_args(args, snip) | ||||
| if args: | ||||
|     snip.rv += '\n' + snip.mkline('', indent='') | ||||
|     snip += '"""' | ||||
| 	snip.rv += '\n' + snip.mkline('', indent='') | ||||
| 	snip += tripple_quotes(snip) | ||||
|  | ||||
| write_init_body(args, t[2], snip) | ||||
| ` | ||||
| @ -330,19 +352,19 @@ endsnippet | ||||
| snippet def "function with docstrings" b | ||||
| def ${1:function}(`!p | ||||
| if snip.indent: | ||||
|    snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}): | ||||
| 	"""${4:@todo: Docstring for $1}`!p | ||||
| 	snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}): | ||||
| 	`!p snip.rv = tripple_quotes(snip)`${4:@todo: Docstring for $1.}`!p | ||||
| snip.rv = "" | ||||
| snip >> 1 | ||||
|  | ||||
| args = get_args(t[2]) | ||||
| if args: | ||||
|    write_docstring_args(args, snip) | ||||
| 	write_docstring_args(args, snip) | ||||
|  | ||||
| style = get_style(snip) | ||||
| snip += format_return(style) | ||||
| snip.rv += '\n' + snip.mkline('', indent='') | ||||
| snip += '"""' ` | ||||
| snip += tripple_quotes(snip) ` | ||||
| 	${0:pass} | ||||
| endsnippet | ||||
|  | ||||
| @ -362,23 +384,57 @@ endsnippet | ||||
| ############## | ||||
| snippet roprop "Read Only Property" b | ||||
| @property | ||||
| def ${1:property}(self): | ||||
| def ${1:name}(self): | ||||
| 	${2:return self._$1}$0 | ||||
| endsnippet | ||||
|  | ||||
| snippet rwprop "Read write property" b | ||||
| def ${1:property}(): | ||||
| 	${2/.+/(?0:""")/}${2:The RW property $1}`!p if t[2]: | ||||
|    snip.rv += '"""' | ||||
|    snip >> 1 | ||||
|    snip += "" | ||||
| def ${1:name}(): | ||||
| 	`!p snip.rv = tripple_quotes(snip) if t[2] else '' | ||||
| `${2:@todo: Docstring for $1.}`!p | ||||
| if t[2]: | ||||
| 	snip >> 1 | ||||
|  | ||||
| 	style = get_style(snip) | ||||
| 	snip.rv += '\n' + snip.mkline('', indent='') | ||||
| 	snip += format_return(style) | ||||
| 	snip.rv += '\n' + snip.mkline('', indent='') | ||||
| 	snip += tripple_quotes(snip) | ||||
| else: | ||||
|    snip.rv = ""`def fget(self): | ||||
| 	snip.rv = ""` | ||||
| 	def fget(self): | ||||
| 		return self._$1$0 | ||||
|  | ||||
| 	def fset(self, value): | ||||
| 		self._$1 = value | ||||
| 	return locals() | ||||
| $1 = property(**$1()) | ||||
|  | ||||
| $1 = property(**$1(), doc=$1.__doc__) | ||||
| endsnippet | ||||
|  | ||||
|  | ||||
| #################### | ||||
| # If / Else / Elif # | ||||
| #################### | ||||
| snippet if "If" b | ||||
| if ${1:condition}: | ||||
| 	${2:pass} | ||||
| endsnippet | ||||
|  | ||||
| snippet ife "If / Else" b | ||||
| if ${1:condition}: | ||||
| 	${2:pass} | ||||
| else: | ||||
| 	${3:pass} | ||||
| endsnippet | ||||
|  | ||||
| snippet ifee "If / Elif / Else" b | ||||
| if ${1:condition}: | ||||
| 	${2:pass} | ||||
| elif ${3:condition}: | ||||
| 	${4:pass} | ||||
| else: | ||||
| 	${5:pass} | ||||
| endsnippet | ||||
|  | ||||
|  | ||||
| @ -430,6 +486,14 @@ snippet pdb "Set PDB breakpoint" b | ||||
| import pdb; pdb.set_trace() | ||||
| endsnippet | ||||
|  | ||||
| snippet ipdb "Set IPDB breakpoint" b | ||||
| import ipdb; ipdb.set_trace() | ||||
| endsnippet | ||||
|  | ||||
| snippet pudb "Set PUDB breakpoint" b | ||||
| import pudb; pudb.set_trace() | ||||
| endsnippet | ||||
|  | ||||
| snippet ae "Assert equal" b | ||||
| self.assertEqual(${1:first},${2:second}) | ||||
| endsnippet | ||||
| @ -453,7 +517,8 @@ endsnippet | ||||
|  | ||||
| snippet testcase "pyunit testcase" b | ||||
| class Test${1:Class}(${2:unittest.TestCase}): | ||||
| 	"""${3:Test case docstring}""" | ||||
|  | ||||
| 	`!p snip.rv = tripple_quotes(snip)`${3:Test case docstring.}`!p snip.rv = tripple_quotes(snip)` | ||||
|  | ||||
| 	def setUp(self): | ||||
| 		${4:pass} | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 amix
					amix