import sublime import sublime_plugin import os from getimageinfo import getImageInfo class InsertDimensionsCommand(sublime_plugin.TextCommand): this_dir = '' def insert_dimension(self,edit,dim,name,tag_scope): view = self.view sel = view.sel()[0].a if name in view.substr(tag_scope): reg = view.find('(?<='+name+'\=)\s*\"\d{1,5}', tag_scope.a) view.replace(edit, reg, '"'+str(dim)) else: dimension = str(dim) view.insert(edit, sel+1, ' '+name+'="'+dimension+'"') def get_setting(self,string,view=None): if view and view.settings().get(string): return view.settings().get(string) else: return sublime.load_settings('autofilename.sublime-settings').get(string) def run(self, edit): view = self.view view.run_command("commit_completion") sel = view.sel()[0].a if not 'html' in view.scope_name(sel): return scope = view.extract_scope(sel-1) tag_scope = view.extract_scope(scope.a-1) path = view.substr(scope) if path.startswith(("'","\"","(")): path = path[1:-1] path = path[path.rfind('/'):] if '/' in path else '' full_path = self.this_dir + path if '