Skip to content

@agibsonsw /PythonCompletions.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Python completions
import sublime, sublime_plugin
import re
def match1(rex, str):
m = rex.match(str)
if m:
return m.group(0)
else:
return None
class PythonCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
# prefix is the current trigger text, locations are
# just points, or sel().
other_comp = view.extract_completions(prefix)
other_comp = [(item, item) for item in other_comp]
# other_comp = list(set(other_comp)) # make unique
# (only necessary if getting compl. from other tabs as well)
if not view.match_selector(locations[0], 'source.python -string -comment -constant'):
return other_comp.sort()
is_sublime = False
if view.find("(?:from|import)\s+sublime",0) is not None: is_sublime = True
py_compl = [
("abs\tabs fn", "abs(${1:number})$0"),
("all\tall fn", "all(${1:iterable})$0"),
("any\tany fn", "any(${1:iterable})$0"),
("basestring\tbasestring type", "basestring$0"),
("bin\tbin fn", "bin(${1:integer})$0"),
("bool\tbool fn", "bool(${1:[value]})$0"),
("bytearray\tbytearray fn",
"bytearray(${1:${2:source}${3:[, encoding]}${4:[, errors]}})$0"),
("callable\tcallable fn", "callable(${1:object})$0"),
("chr\tchr fn", "chr(${1:integer})$0"),
("classmethod\tclassmethod fn", "classmethod(${1:function})$0"),
("cmp\tcmp fn", "cmp(${1:x}, ${2:y})$0"),
("compile\tcompile fn",
"compile(${1:source}, ${2:filename}, ${3:mode}${4:[, flags]}${5:[, dont_inherit]})$0"),
("complex\tcomplex fn", "complex(${1:real}${2:[, imag]})$0"),
("delattr\tdelattr fn", "delattr(${1:object}, ${2:name})$0"),
("dict\tdict fn", "dict(${1:arg})$0"),
("dir\tdir fn", "dir(${1:[object]})$0"),
("divmod\tdivmod fn", "divmod(${1:a}, ${2:b})$0"),
("enumerate\tenumerate fn", "enumerate(${1:sequence}${2:[, start]})$0"),
("eval\teval fn", "eval(${1:expression}${2:[, globals]}${3:[, locals]})$0"),
("execfile\texecfile fn", "execfile(${1:filename}${2:[, globals]}${3:[, locals]})$0"),
("file\tfile fn", "file(${1:filename}${2:[, mode]}${3:[, bufsize]})$0"),
("filter\tfilter fn", "filter(${1:function}, ${2:iterable})$0"),
("float\tfloat fn", "float(${1:[x]})$0"),
("format\tformat fn", "format(${1:value}${2:[, format_spec]})$0"),
("frozenset\tfrozenset fn", "frozenset(${1:[iterable]})$0"),
("getattr\tgetattr fn", "getattr(${1:object}, ${2:name}${3:[, default]})$0"),
("globals\tglobals fn", "globals()$0"),
("hasattr\thasattr fn", "hasattr(${1:object}, ${2:name})$0"),
("hash\thash fn", "hash(${1:object})$0"),
("help\thelp fn", "help(${1:[object]})$0"),
("hex\thex fn", "hex(${1:x})$0"),
("id\tid fn", "id(${1:object})$0"),
("input\tinput fn", "input(${1:[prompt]})$0"),
("int\tint fn", "int(${1:x}${2:[, base]})$0"),
("isinstance\tisinstance fn", "isinstance(${1:object}, ${2:classinfo})$0"),
("issubclass\tissubclass fn", "issubclass(${1:class}, ${2:classinfo})$0"),
("iter\titer fn", "iter(${1:o}${2:[, sentinel]})$0"),
("len\tlen fn", "len(${1:object})$0"),
("list\tlist fn", "list(${1:[iterable]})$0"),
("locals\tlocals fn", "locals()$0"),
("long\tlong fn", "long(${1:x}${2:[, base]})$0"),
("map\tmap fn", "map(${1:function}${2:[, iterables]})$0"),
("max\tmax fn", "max(${1:iterable}${2:[, args]}${3:[, key]})$0"),
("memoryview\tmemoryview fn", "memoryview(${1:object})$0"),
("min\tmin fn", "min(${1:iterable}${2:[, args]}${3:[, key]})$0"),
("next\tnext fn", "next(${1:iterator}${2:[, default]})$0"),
("object\tobject fn", "object()$0"),
("oct\toct fn", "oct(${1:integer})$0"),
("open\topen fn", "open(${1:filename}${2:[, mode]}${3:[, bufsize]})$0"),
("ord\tord fn", "ord(${1:char})$0"),
("pow\tpow fn", "pow(${1:x}, ${2:y}${3:[, modulo]})$0"),
("print\tprint fn",
"print(${1:[object, ...][, sep=' '][, end='\\n'][, file=sys.stdout]})$0"),
("property\tproperty fn", "property(${1:[fget[, fset[, fdel[, doc]]]]})$0"),
("range\trange fn", "range(${1:[start, ]}${2:stop}${3:[, step]})$0"),
("raw_input\traw_input fn", "raw_input(${1:[prompt]})$0"),
("reduce\treduce fn", "reduce(${1:function}, ${2:iterable}${3:[, initializer]})$0"),
("reload\treload fn", "reload(${1:module})$0"),
("repr\trepr fn", "repr(${1:object})$0"),
("reversed\treversed fn", "reversed(${1:seq})$0"),
("round\tround fn", "round(${1:float}${2:[, digits]})$0"),
("set\tset fn", "set(${1:[iterable]})$0"),
("setattr\tsetattr fn", "setattr(${1:object}, ${2:name}, ${3:value})$0"),
("slice\tslice fn", "slice(${1:[start, ]}${2:stop}${3:[, step]})$0"),
("sorted\tsorted fn",
"sorted(${1:iterable}${2:${3:[, cmp]}${4:[, key]}${5:[, reverse]}})$0"),
("staticmethod\tstaticmethod fn", "staticmethod(${1:function})$0"),
("str\tString fn", "str(${1:object})$0"),
("sum\tsum fn", "sum(${1:iterable}${2:[, start]})$0"),
("super\tsuper fn", "super(${1:type}${2:[, object/type]})$0"),
("tuple\ttuple fn", "tuple(${1:[iterable]})$0"),
("type\ttype fn", "type(${1:object})$0"),
("type\ttype ctor", "type(${1:name}, ${2:bases}, ${3:dict})$0"),
("__import__\t__import__ fn",
"__import__(${1:name}${2:[, globals, locals, fromlist, level]})$0"),
("unichr\tunichr fn", "unichr(${1:[integer]})$0"),
("unicode\tunicode fn", "unicode(${1:[object, ]}${2:encoding}${3:[, errors]})$0"),
("vars\tvars fn", "vars(${1:[object]})$0"),
("xrange\txrange fn", "xrange(${1:[start, ]}${2:stop}${3:[, step]})$0"),
("zip\tzip fn", "zip(${1:iterable})$0")
]
if is_sublime:
subl_compl = [
("set_clipboard\tSublime", "set_clipboard(${1:string})$0"),
("set_timeout\tSublime", "set_timeout(${1:callback}, ${2:delay})$0"),
("error_message\tSublime", "error_message(${1:string})$0"),
("status_message\tSublime", "status_message(${1:string})$0")
]
py_compl = py_compl + subl_compl
# py_compl.sort()
# py_compl = (py_compl, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
return py_compl
@agibsonsw
Owner

Python completions for Sublime Text 2.

Comment out the line:
py_compl = (py_compl, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
if you still want the default (file) completions to be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.