def run(self, edit, modifier=1): self.edit = edit self.options = get_hayaku_options(self) # Set the modifier from the direction and amount self.modifier = modifier self.dirty_regions = [] self.multiline = False for index, region in enumerate(self.view.sel()): if self.is_multiline(region): self.multiline = True for line_index in range(0, len(self.view.lines(region))): # Do stuff only if selection on a line contains some non-whitespace chars if len( self.view.substr( self.view.split_by_newlines(self.view.sel( )[index])[line_index]).strip()) > 0: # Process the proper line region (after possible previous changes) self.process_region( self.view.lines( self.view.sel()[index])[line_index], None) self.multiline = False else: self.process_region(region, index)
def run(self, edit): self.edit = edit self.hayaku = {} self.hayaku['options'] = get_hayaku_options(self) self.hayaku['clipboard'] = sublime.get_clipboard() self.retrieve_abbr() if self.hayaku.get('abbr') is None: return self.snippet = make_template(self.hayaku) if self.snippet is None: return self.insert_snippet()
def run(self, edit): result = None # Determine the limits for place searching regions = self.view.sel() region = regions[0] line = self.view.line(region) stop_point = self.view.find('[}]\s*', line.begin()) if stop_point is not None and not (-1, -1): end = stop_point.end() else: end = self.view.find('[^}]*', line.begin()).end() where_to_search = self.view.substr(sublime.Region(line.begin(), end)) options = get_hayaku_options(self) # Insert a code block if we must found_insert_position = re.search('^([^}{]*?[^;,}{\s])\s*(?=\n|$)', where_to_search) if found_insert_position is not None: self.view.sel().clear() self.view.sel().add( sublime.Region( len(found_insert_position.group(1)) + line.begin(), len(found_insert_position.group(1)) + line.begin())) result = hayaku_get_block_snippet(options) else: # Place a caret + create a new line otherwise # FIXME: the newline is not perfectly inserted. Must rethink it so there wouldn't # be replacement of all whitespaces and would be better insertion handling found_insert_rule = re.search('^(([^}]*?[^;]?)\s*)(?=\})', where_to_search) if found_insert_rule is not None: self.view.sel().clear() self.view.sel().add( sublime.Region( len(found_insert_rule.group(2)) + line.begin(), len(found_insert_rule.group(1)) + line.begin())) result = ''.join([ options["CSS_whitespace_block_start_after"], "$0", options["CSS_whitespace_block_end_before"] ]) assert result is not None self.view.run_command("insert_snippet", {"contents": result})
def run(self, edit): result = None # Determine the limits for place searching regions = self.view.sel() region = regions[0] line = self.view.line(region) stop_point = self.view.find('[}]\s*',line.begin()) if stop_point is not None and not (-1, -1): end = stop_point.end() else: end = self.view.find('[^}]*',line.begin()).end() where_to_search = self.view.substr( sublime.Region( line.begin(), end ) ) options = get_hayaku_options(self) # Insert a code block if we must found_insert_position = re.search('^([^}{]*?[^;,}{\s])\s*(?=\n|$)', where_to_search) if found_insert_position is not None: self.view.sel().clear() self.view.sel().add(sublime.Region(len(found_insert_position.group(1)) + line.begin(), len(found_insert_position.group(1)) + line.begin())) result = hayaku_get_block_snippet(options) else: # Place a caret + create a new line otherwise # FIXME: the newline is not perfectly inserted. Must rethink it so there wouldn't # be replacement of all whitespaces and would be better insertion handling found_insert_rule = re.search('^(([^}]*?[^;]?)\s*)(?=\})', where_to_search) if found_insert_rule is not None: self.view.sel().clear() self.view.sel().add(sublime.Region(len(found_insert_rule.group(2)) + line.begin(), len(found_insert_rule.group(1)) + line.begin())) result = ''.join([ options["CSS_whitespace_block_start_after"] , "$0" , options["CSS_whitespace_block_end_before"] ]) assert result is not None self.view.run_command("insert_snippet", {"contents": result})
def run(self, edit, modifier = 1): self.edit = edit self.options = get_hayaku_options(self) # Set the modifier from the direction and amount self.modifier = modifier self.dirty_regions = [] self.multiline = False for index, region in enumerate(self.view.sel()): if self.is_multiline(region): self.multiline = True for line_index in range(0, len(self.view.lines(region))): # Do stuff only if selection on a line contains some non-whitespace chars if len(self.view.substr(self.view.split_by_newlines(self.view.sel()[index])[line_index]).strip()) > 0: # Process the proper line region (after possible previous changes) self.process_region(self.view.lines(self.view.sel()[index])[line_index], None) self.multiline = False else: self.process_region(region, index)
def run(self, edit): # TODO: consume the braces and whitespaces around and inside self.view.run_command("insert_snippet", {"contents": hayaku_get_block_snippet(get_hayaku_options(self),True)})
def run(self, edit): # TODO: consume the braces and whitespaces around and inside self.view.run_command("insert_snippet", { "contents": hayaku_get_block_snippet(get_hayaku_options(self), True) })