Last active
August 20, 2021 07:17
-
-
Save sfinktah/7b0c022db96578254fd52d082a91f8fc to your computer and use it in GitHub Desktop.
UltiSnips auto-completions that don't expand in comments
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
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