# -*- coding: utf-8 -*-
import sublime_plugin, re
class PlaceImageCommand(sublime_plugin.EventListener):
def __init__(self):
self.pi_snip = ''
self.placeit = ''
self.kitten = ''
self.pattern = r'^pi(?:(\d+)(?:(x|X)(\d+))?)?$'
def on_query_completions(self, view, prefix, locations):
match = re.match(self.pattern, prefix)
if match:
groups = match.groups()
numNil = groups.count(None)
# handle tab trigger: `pi`
if numNil == 3:
value = self.pi_snip
# handle tab trigger: `pi{numbers}`
elif numNil == 2:
width = groups[0]
height = width
value = self.placeit % ((width, height) * 3)
# handle tab trigger: `pi{width}(x|X){height}`
else:
width = groups[0]
height = groups[2]
source = self.placeit if groups[1] == 'x' else self.kitten
value = source % ((width, height) * 3)
else:
value = None
return [(prefix, prefix, value)] if value else []