SublimeText/GenerateUUID — Issue #1: Insert uuid on tab
Author: robcowie
Created: 2011-12-16 23:47:40+00:00
State: open

Insertion of a uuid on `'uuid' + tab` is imho much easier than via the command palette. I've been using the following event listener for a couple of months and it seems to work well.

class UUIDCommand(sublime_plugin.EventListener):
"""Expand `uuid` and `uuid4` to a random uuid (uuid4) and `uuid1` to a
uuid based on host and current time (uuid1)
"""
def on_query_completions(self, view, prefix, locations):
if prefix in ('uuid', 'uuid4'): ## random
val = uuid.uuid4()
elif prefix == 'uuid1': ## host and current time
val = uuid.uuid1()
else:
return []
return [(prefix, prefix, str(val))] if val else []