Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Last active August 29, 2015 13:56
Show Gist options
  • Save mgedmin/8936596 to your computer and use it in GitHub Desktop.
Save mgedmin/8936596 to your computer and use it in GitHub Desktop.
Attempt to write a smart super() snippet for UltiSnips
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