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, "@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 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")