Beispiel #1
0
    def open_(self, sender):
        from editxt import app
        from editxt.textcommand import iterlines

        paths = iterlines(self.paths.textStorage().string())
        app.open_documents_with_paths([p.strip() for p in paths if p.strip()])
        self.window().orderOut_(self)
Beispiel #2
0
def sortlines(textview, opts):
    text = textview.string()
    regex = re.compile(opts.search_pattern) if opts.regex_sort else None
    if opts.match_pattern:
        groups = [int(g.strip()) for g in opts.match_pattern.split("\\") if g.strip()]
    else:
        groups = None
    def key(line):
        if opts.ignore_leading_ws:
            line = line.lstrip()
        if regex is not None:
            match = regex.search(line)
            if match is None:
                line = (1,)
            elif not match.groups():
                line = (0, match.group(0))
            else:
                matched = match.groups("")
                if groups:
                    matched = dict(enumerate(matched))
                    matched = tuple(matched.get(g - 1, "") for g in groups)
                line = (0,) + matched
        return line
    if opts.sort_selection:
        range = text.lineRangeForRange_(textview.selectedRange())
    else:
        range = (0, len(text))
    output = "".join(sorted(iterlines(text, range), key=key, reverse=opts.reverse_sort))
    if textview.shouldChangeTextInRange_replacementString_(range, output):
        textview.textStorage().replaceCharactersInRange_withString_(range, output)
        textview.didChangeText()
        if opts.sort_selection:
            textview.setSelectedRange_(range)
Beispiel #3
0
def wrap_selected_lines(textview, options):
    text = textview.string()
    sel = text.lineRangeForRange_(textview.selectedRange())
    eol = textview.doc_view.document.eol
    lines = iterlines(text, sel)
    output = eol.join(wraplines(lines, options, textview))
    if textview.shouldChangeTextInRange_replacementString_(sel, output):
        textview.textStorage().replaceCharactersInRange_withString_(sel, output)
        textview.didChangeText()
        textview.setSelectedRange_((sel[0], len(output)))
Beispiel #4
0
    def analyze_content(self):
        from editxt.textcommand import iterlines

        text = self.text_storage.string()
        start, end, cend = text.getLineStart_end_contentsEnd_forRange_(None, None, None, (0, 0))
        if end != cend:
            eol = EOLREF.get(text[cend:end], const.NEWLINE_MODE_UNIX)
            self.newline_mode = eol
        mode = None
        for line in iterlines(text):
            if line.startswith(u"\t"):
                mode = const.INDENT_MODE_TAB
                if line.strip():
                    break
            elif line.startswith(u" "):
                mode = const.INDENT_MODE_SPACE
                if line.strip():
                    self.indent_size = len(line) - len(line.lstrip(u" "))
                    break
        if mode is not None:
            self.indent_mode = mode