def paint_it(self, color, match_position, length, start_position, end_position): ''' This is where the actual coloring takes place. Color, the position of the first character and the length of the text to be colored must be provided. Coloring occurs only if the character at the current position has not a style from the excluded styles list assigned. Args: color = integer, expected in range of 0-16777215 match_position = integer, denotes the start position of a match length = integer, denotes how many chars need to be colored. start_position = integer, denotes the start position of the visual area end_position = integer, denotes the end position of the visual area Returns: None ''' if (match_position + length < start_position or match_position > end_position or editor.getStyleAt(match_position) in self.excluded_styles): return editor.setIndicatorCurrent(0) editor.setIndicatorValue(color) editor.indicatorFillRange(match_position, length)
def style(self): ''' Calculates the text area to be searched for in the current document. Calls up the regexes to find the position and calculates the length of the text to be colored. Deletes the old indicators before setting new ones. Args: None Returns: None ''' start_line = editor.docLineFromVisible(editor.getFirstVisibleLine()) end_line = editor.docLineFromVisible(start_line + editor.linesOnScreen()) if editor.getWrapMode(): end_line = sum([editor.wrapCount(x) for x in range(end_line)]) onscreen_start_position = editor.positionFromLine(start_line) onscreen_end_pos = editor.getLineEndPosition(end_line) editor.setIndicatorCurrent(0) editor.indicatorClearRange(0, editor.getTextLength()) for color, regex in self.regexes.items(): editor.research( regex[0], lambda m: self.paint_it( color[1], m.span(regex[1])[0], m.span(regex[1])[1] - m.span(regex[1])[0], onscreen_start_position, onscreen_end_pos), 0, onscreen_start_position, onscreen_end_pos)
def do_regex(self, regex, indicator, start_position, end_position): editor.setIndicatorCurrent(indicator) editor.indicatorClearRange(start_position, end_position-start_position) editor.research(regex[0], lambda m: self.paint_it(indicator, m.span(regex[1])[0], m.span(regex[1])[1] - m.span(regex[1])[0]), 0, start_position, end_position)
def paint_it(indicator, pos, length): current_line = editor.lineFromPosition(pos) line_start_position = editor.positionFromLine(current_line) text = editor.getLine(current_line) found_comment_char = text.find('#') relative_line_position = pos - line_start_position if ((-1 < found_comment_char < relative_line_position) or (text.count('"', 0, relative_line_position) % 2 == 1) or (text.count("'", 0, relative_line_position) % 2 == 1)): return else: editor.setIndicatorCurrent(indicator) editor.indicatorFillRange(pos, length)
def paint_it(indicator, pos, length): current_line = editor.lineFromPosition(pos) line_start_position = editor.positionFromLine(current_line) text = editor.getLine(current_line) found_comment_char = text.find('#') relative_line_position = pos-line_start_position if((-1 < found_comment_char < relative_line_position) or (text.count('"', 0, relative_line_position) % 2 == 1) or (text.count("'", 0, relative_line_position) % 2 == 1)): return else: editor.setIndicatorCurrent(indicator) editor.indicatorFillRange(pos,length)
def style(self): line_number = editor.getFirstVisibleLine() start_position = editor.positionFromLine(line_number) end_position = editor.getLineEndPosition(line_number + editor.linesOnScreen()) editor.setIndicatorCurrent(self.indicator) editor.indicatorClearRange(start_position, end_position - start_position) flag = 0 editor.research( '^# ?%%(.*)$', lambda m: self.paint_it(self.indicator, m.span(flag)[0], m.span(flag)[1] - m.span(flag)[0]), 0, start_position, end_position)
def paint_it(indicator, pos, length): current_line = editor.lineFromPosition(pos) editor.setIndicatorCurrent(indicator) editor.indicatorFillRange(pos, length)