def get_color(self, raw_line): color = 7 line = raw_line.strip() if helpers.starts(line, ["{", "}"]): color = 3 # Blue elif helpers.starts(line, "\""): color = 2 # Green return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() if helpers.starts(line, ["{", "}"]): color = color_map["yellow"] elif helpers.starts(line, "\""): color = color_map["green"] return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() if helpers.starts(line, ["*", "-"]): # List color = color_map["cyan"] elif helpers.starts(line, "#"): # Header color = color_map["green"] elif helpers.starts(line, ">"): # Item desription color = color_map["yellow"] elif helpers.starts(raw_line, " "): # Code color = color_map["magenta"] return color
def get_color(self, raw_line): color = 7 line = raw_line.strip() if helpers.starts(line, ["*", "-"]): # List color = 6 # Cyan elif helpers.starts(line, "#"): # Header color = 2 # Green elif helpers.starts(line, ">"): # Item desription color = 3 # Yellow elif helpers.starts(raw_line, " "): # Code color = 5 # Magenta return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() if helpers.starts(line, ["#", "//", "/*", "*/", "<!--"]): color = color_map["magenta"] elif helpers.ends(line, ["*/", "-->"]): color = color_map["magenta"] elif helpers.starts(line, "<"): color = color_map["cyan"] elif helpers.ends(line, ">"): color = color_map["cyan"] return color
def get_color(self, raw_line): color = 7 line = raw_line.strip() if helpers.starts(line, ["#", "//", "/*", "*/", "<!--"]): color = 5 # Magenta elif helpers.ends(line, ["*/", "-->"]): color = 5 # Magenta elif helpers.starts(line, "<"): color = 6 # Cyan elif helpers.ends(line, ">"): color = 6 # Cyan return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() if helpers.starts(line, "@import"): color = color_map["blue"] elif helpers.starts(line, "$"): color = color_map["green"] elif helpers.starts(line, "/*") or helpers.ends(line, "*/"): color = color_map["magenta"] elif helpers.starts(line, "{") or helpers.ends(line, "}") or helpers.ends(line, "{"): color = color_map["cyan"] elif helpers.ends(line, ";"): color = color_map["yellow"] return color
def get_color(self, raw_line): color = 7 line = raw_line.strip() if helpers.starts(line, "@import"): color = 4 # Blue elif helpers.starts(line, "$"): color = 2 # Green elif helpers.starts(line, "/*") or helpers.ends(line, "*/"): color = 5 # Magenta elif helpers.starts(line, "{") or helpers.ends(line, "}") or helpers.ends(line, "{"): color = 6 # Cyan elif helpers.ends(line, ";"): color = 3 # Yellow return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() if helpers.starts(line, "function"): color = color_map["cyan"] elif helpers.starts(line, ["return"]): color = color_map["red"] elif helpers.starts(line, "this."): color = color_map["cyan"] elif helpers.starts(line, ["//", "/*", "*/", "*"]): color = color_map["magenta"] elif helpers.starts(line, ["if", "else", "for ", "while ", "continue", "break"]): color = color_map["yellow"] return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() if helpers.starts(line, "@import"): color = color_map["blue"] elif helpers.starts(line, "$"): color = color_map["green"] elif helpers.starts(line, "/*") or helpers.ends(line, "*/"): color = color_map["magenta"] elif helpers.starts(line, "{") or helpers.ends( line, "}") or helpers.ends(line, "{"): color = color_map["cyan"] elif helpers.ends(line, ";"): color = color_map["yellow"] return color
def get_match(self, word): """Find a completable match for word. :param word: The partial word to complete :return: The completion to add to the partial word :rtype: str """ if not word: return False # Build list of suitable matches candidates = [] for candidate in self.word_list: if helpers.starts(candidate, word) and len(candidate) > len(word): candidates.append(candidate) # Find the shortest match # TODO: implement cycling through matches shortest = "" for candidate in candidates: if not shortest: shortest = candidate continue if len(candidate) < len(shortest): shortest = candidate if shortest: return shortest[len(word):] return False
def get_function_returns(self, editor, line_number): """Returns True if function at line_number returns something. :param editor: Editor instance to get lines from. :param line_number: Line number of the function definition. :return: Boolean indicating wether the function something. """ i = line_number + 1 while i < len(editor.lines): line = editor.get_line(i) data = line.get_data().strip() if helpers.starts(data, "def "): break if helpers.starts(data, "return "): return True i += 1 return False
def get_function_returns(self, editor, line_number): """Returns True if function at line_number returns something. :param editor: Editor instance to get lines from. :param line_number: Line number of the function definition. :return: Boolean indicating wether the function something. """ i = line_number+1 while i < len(editor.lines): line = editor.get_line(i) data = line.get_data().strip() if helpers.starts(data, "def "): break if helpers.starts(data, "return "): return True i += 1 return False
def run(self, app, editor, args): """Run the autosphinx command.""" cursor = editor.get_cursor() line = editor.get_line(cursor.y) line_data = line.get_data() if not helpers.starts(line_data.strip(), "def "): app.set_status("Current line isn't a function definition.") return False func_args = self.get_function_args(line_data) func_returns = self.get_function_returns(editor, cursor.y) docstring = self.get_docstring(func_args=func_args, func_returns=func_returns) indent = self.get_docstring_indent(line_data) indent = indent * self.app.config["editor"]["tab_width"] * " " self.insert_docstring(editor, cursor.y+1, indent, docstring)
def run(self, app, editor, args): """Run the autosphinx command.""" cursor = editor.get_cursor() line = editor.get_line(cursor.y) line_data = line.get_data() if not helpers.starts(line_data.strip(), "def "): app.set_status("Current line isn't a function definition.") return False func_args = self.get_function_args(line_data) func_returns = self.get_function_returns(editor, cursor.y) docstring = self.get_docstring(func_args=func_args, func_returns=func_returns) indent = self.get_docstring_indent(line_data) indent = indent * self.app.config["editor"]["tab_width"] * " " self.insert_docstring(editor, cursor.y + 1, indent, docstring)
def run(self, app, editor, args): """Comment the current line(s).""" try: # Try to get comment start and end syntax comment = editor.syntax.get_comment() except: return False line_nums = editor.get_lines_with_cursors() # Iterate through lines for lnum in line_nums: line = editor.lines[lnum] if not len(line): continue # Skip empty lines # Look for comment syntax in stripped line (TODO:Make this smarter) target = str(line).strip() w = helpers.whitespace(line) # Amount of whitespace at line start # If the line starts with comment syntax if helpers.starts(target, comment[0]): # Reconstruct the whitespace and add the line new_line = (" " * w) + line[w + len(comment[0]):] # If comment end syntax exists if comment[1]: # Try to remove it from the end of the line if helpers.ends(new_line, comment[1]): new_line = new_line[:-1 * len(comment[1])] # Store the modified line # editor.lines[lnum] = Line(new_line) editor.lines[lnum].set_data(new_line) # If the line isn't commented else: # Slice out the prepended whitespace new_line = line[w:] # Add the whitespace and starting comment new_line = (" " * w) + comment[0] + new_line if comment[1]: # Add comment end syntax if needed new_line += comment[1] # Store modified line # editor.lines[lnum] = Line(new_line) editor.lines[lnum].set_data(new_line) # Keep cursors under control, same as usual... editor.move_cursors() editor.store_action_state("comment")
def run(self, app, editor, args): """Comment the current line(s).""" try: # Try to get comment start and end syntax comment = editor.syntax.get_comment() except: return False line_nums = editor.get_lines_with_cursors() # Iterate through lines for lnum in line_nums: line = editor.lines[lnum] if not len(line): continue # Skip empty lines # Look for comment syntax in stripped line (TODO:Make this smarter) target = str(line).strip() w = helpers.whitespace(line) # Amount of whitespace at line start # If the line starts with comment syntax if helpers.starts(target, comment[0]): # Reconstruct the whitespace and add the line new_line = (" "*w) + line[w+len(comment[0]):] # If comment end syntax exists if comment[1]: # Try to remove it from the end of the line if helpers.ends(new_line, comment[1]): new_line = new_line[:-1*len(comment[1])] # Store the modified line # editor.lines[lnum] = Line(new_line) editor.lines[lnum].set_data(new_line) # If the line isn't commented else: # Slice out the prepended whitespace new_line = line[w:] # Add the whitespace and starting comment new_line = (" "*w) + comment[0] + new_line if comment[1]: # Add comment end syntax if needed new_line += comment[1] # Store modified line # editor.lines[lnum] = Line(new_line) editor.lines[lnum].set_data(new_line) # Keep cursors under control, same as usual... editor.move_cursors() editor.store_action_state("comment")
def get_color(self, raw_line): color = 7 line = raw_line.strip() if helpers.starts(line, ["import", "from"]): color = 4 # Blue elif helpers.starts(line, "function"): color = 6 # Cyan elif helpers.starts(line, ["return"]): color = 1 # Red elif helpers.starts(line, "this."): color = 6 # Cyan elif helpers.starts(line, ["//", "/*", "*/", "*"]): color = 5 # Magenta elif helpers.starts(line, ["if", "else", "for ", "while ", "continue", "break"]): color = 3 # Yellow return color
def get_color(self, raw_line): color = 7 line = raw_line.strip() keywords = ["if", "elif", "else", "finally", "try", "except", "for ", "while ", "continue", "pass", "break"] if helpers.starts(line, ["import", "from"]): color = 4 # Blue elif helpers.starts(line, "class"): color = 2 # Green elif helpers.starts(line, "def"): color = 6 # Cyan elif helpers.starts(line, ["return", "yield"]): color = 1 # Red elif helpers.starts(line, "self."): color = 6 # Cyan elif helpers.starts(line, ["#", "//", "\"", "'", ":"]): color = 5 # Magenta elif helpers.starts(line, keywords): color = 3 # Yellow return color
def get_color(self, raw_line): color = 7 line = raw_line.strip() keywords = ["if", "else", "finally", "try", "catch", "foreach", "while", "continue", "pass", "break"] if helpers.starts(line, ["include", "require"]): color = 4 # Blue elif helpers.starts(line, ["class", "public", "private", "function"]): color = 2 # Green elif helpers.starts(line, "def"): color = 6 # Cyan elif helpers.starts(line, ["return"]): color = 1 # Red elif helpers.starts(line, "$"): color = 6 # Cyan elif helpers.starts(line, ["#", "//", "/*", "*/"]): color = 5 # Magenta elif helpers.starts(line, keywords): color = 3 # Yellow return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() keywords = ["if", "elif", "else", "finally", "try", "except", "for ", "while ", "continue", "pass", "break"] if helpers.starts(line, ["import", "from"]): color = color_map["blue"] elif helpers.starts(line, "class"): color = color_map["green"] elif helpers.starts(line, "def"): color = color_map["cyan"] elif helpers.starts(line, ["return", "yield"]): color = color_map["red"] elif helpers.starts(line, "self."): color = color_map["cyan"] elif helpers.starts(line, ["#", "//", "\"", "'", ":"]): color = color_map["magenta"] elif helpers.starts(line, keywords): color = color_map["yellow"] return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() keywords = ["if", "else", "finally", "try", "catch", "foreach", "while", "continue", "pass", "break"] if helpers.starts(line, ["include", "require"]): color = color_map["blue"] elif helpers.starts(line, ["class", "public", "private", "function"]): color = color_map["green"] elif helpers.starts(line, "def"): color = color_map["cyan"] elif helpers.starts(line, ["return"]): color = color_map["red"] elif helpers.starts(line, "$"): color = color_map["cyan"] elif helpers.starts(line, ["#", "//", "/*", "*/"]): color = color_map["magenta"] elif helpers.starts(line, keywords): color = color_map["yellow"] return color
def get_color(self, raw_line): color = color_map["white"] line = raw_line.strip() keywords = [ "if", "elif", "else", "finally", "try", "except", "for ", "while ", "continue", "pass", "break" ] if helpers.starts(line, ["import", "from"]): color = color_map["blue"] elif helpers.starts(line, "class"): color = color_map["green"] elif helpers.starts(line, "def"): color = color_map["cyan"] elif helpers.starts(line, ["return", "yield"]): color = color_map["red"] elif helpers.starts(line, "self."): color = color_map["cyan"] elif helpers.starts(line, ["#", "//", "\"", "'", ":"]): color = color_map["magenta"] elif helpers.starts(line, keywords): color = color_map["yellow"] return color