def run(self, edit): cur_pos = self.view.sel()[0].begin() start_pos = cur_pos - MAX_SIZE_CSS if start_pos < 0: start_pos = 0 # TODO: Move this to the contexts, it's not needed here probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos)) match = ABBR_REGEX.search(probably_abbr) if match is None: self.view.insert(edit, cur_pos, '\t') return abbr = match.group(1) # Extracting the data from the abbr args = extract(abbr) if not args: return # Getting the options and making a snippet # from the extracted data get_hayaku_options(self) options = get_hayaku_options(self) template = make_template(args, options) if template is None: return # Inserting the snippet new_cur_pos = cur_pos - len(abbr) assert cur_pos - len(abbr) >= 0 self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos)) self.view.run_command("insert_snippet", {"contents": template})
def run(self, edit): regions = self.view.sel() if len(regions) > 1: # разобраться с многооконными выборками # пока что работаем только с одним регионом for r in regions: self.view.insert(edit, r, '\t') return region = regions[0] if not region.empty(): # сделать работы с выделенным словом self.view.insert(edit, region, '\t') return cur_pos = region.begin() start_pos = cur_pos - MAX_SIZE_CSS if start_pos < 0: start_pos = 0 probably_abbr = self.view.substr(sublime.Region(start_pos, cur_pos)) match = ABBR_REGEX.search(probably_abbr) if match is None: self.view.insert(edit, cur_pos, '\t') return abbr = match.group(1) # print repr(abbr), 'abbr' extracted = extract(abbr) # print extracted, '1' if not extracted[0]: return # print extracted, '2' template = make_template(self.view.settings().get("hayaku_CSS_whitespace_after_colon"), *extracted) new_cur_pos = cur_pos-len(abbr) assert cur_pos-len(abbr) >= 0 self.view.erase(edit, sublime.Region(new_cur_pos, cur_pos)) self.view.run_command("insert_snippet", {"contents": template})