Skip to content

Instantly share code, notes, and snippets.

@sfinktah
Last active August 20, 2021 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfinktah/7b0c022db96578254fd52d082a91f8fc to your computer and use it in GitHub Desktop.
Save sfinktah/7b0c022db96578254fd52d082a91f8fc to your computer and use it in GitHub Desktop.
UltiSnips auto-completions that don't expand in comments
global !p
pythonZones = [ 'pythonStatement', 'pythonConditional', 'pythonRepeat',
'pythonOperator', 'pythonException', 'pythonInclude', 'pythonAsync',
'pythonDecorator', 'pythonDecoratorName', 'pythonFunction',
'pythonTodo', 'pythonString', 'pythonRawString', 'pythonQuotes',
'pythonTripleQuotes', 'pythonEscape', 'pythonNumber', 'pythonBuiltin',
'pythonExceptions', 'pythonSpaceError', 'pythonDoctest', 'pythonDoctestValue']
commentZones = ['pythonComment']
pythonZoneIds = vim.eval('map('+str(pythonZones)+", 'hlID(v:val)')")
commentZoneIds = vim.eval('map('+str(commentZones)+", 'hlID(v:val)')")
def isCode():
""" https://vi.stackexchange.com/a/18494/10033 """
synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
print("synstackids: {} commentZoneIds: {} pythonZoneIds: {}" \
.format(synstackids, commentZoneIds, pythonZoneIds))
if not synstackids:
return True
if not set(synstackids).isdisjoint(pythonZoneIds):
return True
return False
endglobal
context "isCode()"
snippet /(\S.*) unless / "unless" rA
if not $1:
`!p snip.rv = match.group(1)`
$0
endsnippet
context "isCode()"
snippet 'return unless' "return unless" wA
if not $1:
print("return_unless: $1")
return $2
$0
endsnippet
context "isCode()"
snippet 'return if' "return if" wA
if $1:
print("return_if: $1")
return $2
$0
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment