feat(SublimeText2.WebPackages): cache packages
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import sys
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
|
||||
from trackers import back_track, track_regex, track_scope
|
||||
|
||||
__authors__ = ['"Sergey Chikuyonok" <serge.che@gmail.com>'
|
||||
'"Nicholas Dudfield" <ndudfield@gmail.com>']
|
||||
|
||||
HTML = 'text.html - source'
|
||||
XML = 'text.xml'
|
||||
|
||||
HTML_INSIDE_TAG_ANYWHERE = 'text.html meta.tag'
|
||||
HTML_INSIDE_TAG = ( 'text.html meta.tag - string - '
|
||||
'meta.scope.between-tag-pair.html '
|
||||
'-punctuation.definition.tag.begin.html')
|
||||
|
||||
HTML_INSIDE_TAG_ATTRIBUTE = 'text.html meta.tag string'
|
||||
|
||||
HTML_NOT_INSIDE_TAG = 'text.html - meta.tag'
|
||||
|
||||
NO_PLUG = sublime.INHIBIT_EXPLICIT_COMPLETIONS
|
||||
NO_BUF = sublime.INHIBIT_WORD_COMPLETIONS
|
||||
|
||||
EMMET_SCOPE = ', '.join([HTML, XML])
|
||||
|
||||
def find_tag_start(view, start_pt):
|
||||
regions = back_track(view, start_pt, track_regex('<', False) )
|
||||
return regions[-1].begin()
|
||||
|
||||
def find_tag_name(view, start_pt):
|
||||
tag_region = view.find('[a-zA-Z:]+', find_tag_start(view, start_pt))
|
||||
name = view.substr( tag_region )
|
||||
return name
|
||||
|
||||
def find_attribute_name(view, start_pt):
|
||||
conds = track_scope('string'), track_regex('\s|='), track_regex('\S')
|
||||
regions = back_track(view, start_pt, *conds)
|
||||
return view.substr(regions[-1])
|
||||
|
||||
def remove_html_completions():
|
||||
for completer in "TagCompletions", "HtmlCompletions":
|
||||
try:
|
||||
import html_completions
|
||||
cm = getattr(html_completions, completer)
|
||||
except (ImportError, AttributeError):
|
||||
continue
|
||||
|
||||
completions = sublime_plugin.all_callbacks['on_query_completions']
|
||||
for i, instance in enumerate (completions):
|
||||
if isinstance(instance, cm):
|
||||
del completions[i]
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
#coding: utf8
|
||||
#################################### IMPORTS ###################################
|
||||
|
||||
# Std Libs
|
||||
import re
|
||||
|
||||
# Sublime Libs
|
||||
import sublime
|
||||
import sublime_plugin
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
################################### CONSTANTS ##################################
|
||||
|
||||
# Directions for tracker
|
||||
BACK = -1
|
||||
FORWARD = 1
|
||||
|
||||
###################### VIEW TRACKERS ( CONTEXT SCANNERS ) ######################
|
||||
|
||||
def pt_range(view, start_pt, direction):
|
||||
end_pt = direction
|
||||
if end_pt != -1: end_pt = view.size()
|
||||
return xrange(start_pt, end_pt, direction)
|
||||
|
||||
def region_from_pt_list(l):
|
||||
if l:
|
||||
l = sorted(l)
|
||||
return sublime.Region(l[0], l[-1]+1)
|
||||
|
||||
def view_tracker(view, start_pt, *conds):
|
||||
pts = defaultdict(list)
|
||||
failed = False
|
||||
|
||||
for i, (direction, condition) in enumerate(conds):
|
||||
for pt in pt_range(view, start_pt, direction):
|
||||
if failed: break
|
||||
|
||||
if not condition(view, pt):
|
||||
if not pts[i]: failed = True
|
||||
start_pt = pt
|
||||
break
|
||||
|
||||
if len(pts[i]) < 2:
|
||||
pts[i].append(pt)
|
||||
else:
|
||||
pts[i][-1] = pt
|
||||
|
||||
return [ region_from_pt_list(pt_list) for pt_list in pts.values() ]
|
||||
|
||||
def tracker_success(regions):
|
||||
return all(r is not None for r in regions)
|
||||
|
||||
def back_track(view, start_pt, *conds):
|
||||
return view_tracker(view, start_pt -1, *((BACK, c) for c in conds))
|
||||
|
||||
################################### TRACKERS ###################################
|
||||
|
||||
def track_regex(r, cond=True):
|
||||
return lambda v, p: bool(re.match(r, v.substr(p))) is cond
|
||||
|
||||
def track_scope(s, cond=True):
|
||||
return lambda v, p: bool(v.match_selector(p, s)) is cond
|
||||
|
||||
################################################################################
|
Reference in New Issue
Block a user