Blacklist scopes setting

This commit is contained in:
Liam Cain
2013-07-06 20:35:47 -04:00
parent f09ba1700f
commit b510c04b0e
3 changed files with 13 additions and 10 deletions

View File

@@ -81,8 +81,8 @@ class InsertDimensionsCommand(sublime_plugin.TextCommand):
if '<img' in view.substr(tag_scope) and path.endswith(('.png','.jpg','.jpeg','.gif')):
with open(full_path,'rb') as r:
read_data = r.read() # if path.endswith(('.jpg','.jpeg')) else r.read(24)
con_type, w, h = getImageInfo(read_data)
read_data = r.read() if path.endswith(('.jpg','.jpeg')) else r.read(24)
w, h = getImageInfo(read_data)
if self.get_setting('afn_insert_width_first',view):
self.insert_dimension(edit,h,'height',tag_scope)
self.insert_dimension(edit,w,'width',tag_scope)
@@ -165,8 +165,8 @@ class FileNameComplete(sublime_plugin.EventListener):
if fn.endswith(('.png','.jpg','.jpeg','.gif')):
path = os.path.join(sdir, fn)
with open(path,'rb') as r:
read_data = r.read() # if path.endswith(('.jpg','.jpeg')) else r.read(24)
con_type, w, h = getImageInfo(read_data)
read_data = r.read() if path.endswith(('.jpg','.jpeg')) else r.read(24)
w, h = getImageInfo(read_data)
return fn+'\t'+'w:'+ str(w) +" h:" + str(h)
return fn
@@ -187,6 +187,7 @@ class FileNameComplete(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
is_proj_rel = self.get_setting('afn_use_project_root',view)
valid_scopes = self.get_setting('afn_valid_scopes',view)
blacklist = self.get_setting('afn_blacklist_scopes', view)
uses_keybinding = self.get_setting('afn_use_keybinding', view)
sel = view.sel()[0].a
@@ -198,6 +199,9 @@ class FileNameComplete(sublime_plugin.EventListener):
if not any(s in view.scope_name(sel) for s in valid_scopes):
return
if any(s in view.scope_name(sel) for s in blacklist):
return []
cur_path = self.get_cur_path(view, sel)
if is_proj_rel and cur_path.startswith('/') or cur_path.startswith('\\'):

View File

@@ -18,6 +18,9 @@
// Specify which scopes will trigger AutoFileName
"afn_valid_scopes":["string","css","sass","less","scss"],
// BlackList specific scopes
"afn_blacklist_scopes":["string.regexp.js"],
// Whether or not AutoFileName should insert the width
// and height dimensions after inserting an image into
// an image tag

View File

@@ -23,25 +23,21 @@ def getImageInfo(data):
# and finally the 4-byte width, height
elif ((size >= 24) and data[:8] == b'\211PNG\r\n\032\n'
and (data[12:16] == b'IHDR')):
content_type = 'image/png'
w, h = struct.unpack(">LL", data[16:24])
width = int(w)
height = int(h)
# Maybe this is for an older PNG version.
elif (size >= 16) and data[:8] == b'\211PNG\r\n\032\n':
print("we have a png2")
# Check to see if we have the right content type
content_type = 'image/png'
w, h = struct.unpack(">LL", data[8:16])
width = int(w)
height = int(h)
# handle JPEGs
# Can't get this method to work.
# elif (size >= 2) and data[:2] == b'\377\330':
# content_type = 'image/jpeg'
# jpeg = io.StringIO(olddata)
# print(bytes(ord(jpeg.read(1))))
# jpeg.read(2)
# b = jpeg.read(1)
# try:
@@ -62,4 +58,4 @@ def getImageInfo(data):
# except ValueError:
# pass
return content_type, width, height
return width, height