Last active
August 29, 2015 13:56
-
-
Save mgedmin/8936596 to your computer and use it in GitHub Desktop.
Attempt to write a smart super() snippet for UltiSnips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
snippet super "super()" !b | |
`!p | |
# Set a fallback completion first | |
# snip.rv = 'super(${1:ClassName}, self).${2:method}(' <-- does not work | |
snip.rv = 'super(' | |
import vim | |
# this needs pythonhelper.vim | |
tag = vim.eval('TagInStatusLine()') | |
if tag: | |
# pythonhelper.vim's TagInStatusLine() returns '[in SomeClass.some_method (method)]' | |
tag = tag.strip('[]') | |
if tag.startswith('in '): | |
tag = tag[3:] | |
tag = tag.partition(' (')[0] | |
if '.' in tag: | |
class_name, dot, method_name = tag.partition('.') | |
snip.rv = 'super(%s, self).%s(' % (class_name, method_name) | |
`$1) | |
endsnippet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment