def unindent(editor, text): """ Unindent content, thus preparing text for tag wrapping @param editor: Editor instance @type editor: ZenEditor @param text: str @return str """ pad = get_current_line_padding(editor) lines = zen.split_by_lines(text) for i,line in enumerate(lines): if line.find(pad) == 0: lines[i] = line[len(pad):] return zen.get_newline().join(lines)
def merge_lines(editor): """ Merge lines spanned by user selection. If there's no selection, tries to find matching tags and use them as selection @param editor: Editor instance @type editor: ZenEditor """ start, end = editor.get_selection_range() if start == end: # find matching tag pair = html_matcher.match(editor.get_content(), editor.get_caret_pos()) if pair and pair[0] is not None: start, end = pair if start != end: # got range, merge lines text = editor.get_content()[start, end] lines = map(lambda s: re.sub(r'^\s+', '', s), zen.split_by_lines(text)) text = re.sub(r'\s{2,}', ' ', ''.join(lines)) editor.replace_content(text, start, end) editor.create_selection(start, start + len(text))