コード例 #1
0
        def f(view, s):
            is_last_iteration = (current_iteration == total_iterations - 1)

            if mode == _MODE_INTERNAL_NORMAL:
                    # If we're at BOL one LINE down; move to NEXTWORD WORDEND inclusive.
                    if utils.is_at_bol(self.view, s):
                        next = utils.next_non_white_space_char(self.view, s.b, white_space='\t \n')
                        next = self.view.word(next)
                        return sublime.Region(s.a, next.b)
                    else:
                        return s

            elif mode == MODE_NORMAL:
                    # If we're at BOL one LINE down; move to NEXTWORD WORDEND exclusive.
                    if utils.is_at_bol(self.view, s):
                        next = utils.next_non_white_space_char(self.view, s.b, white_space='\t \n')
                        next = self.view.word(next)
                        return sublime.Region(next.b - 1, next.b - 1)
                    # Last motion; ensure caret ends up at a WORDEND exclusive. The native 'move'
                    # command will have left us on the next character.
                    elif is_last_iteration:
                        return sublime.Region(s.a - 1, s.b - 1)
                    else:
                        return s

            elif mode == MODE_VISUAL:
                # If we're at BOL one LINE down, move to NEXTWORD WORDEND inclusive.
                if utils.is_at_bol(self.view, s):
                    next = utils.next_non_white_space_char(self.view, s.b, white_space='\t \n')
                    next = self.view.word(next)
                    return sublime.Region(s.a, next.b)
                else:
                    return s
コード例 #2
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [
                fragments[0],
            ] * len(sels))

        offset = 0
        for s, text in sel_frag:
            if text.endswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(
                        self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).a, text, count)
                else:
                    self.paste_all(edit, s,
                                   self.view.line(s.b - 1).a, text, count)
            else:
                self.paste_all(edit, s, s.b + offset, text, count)
                offset += len(text) * count
コード例 #3
0
ファイル: actions.py プロジェクト: ahnan4arch/Vintageous
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            if text.endswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).a, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).a, text, count)
            else:
                self.paste_all(edit, s, s.b + offset, text, count)
                offset += len(text) * count
コード例 #4
0
ファイル: action_cmds.py プロジェクト: corelon/Vintageous
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            text = self.prepare_fragment(text)
            if text.startswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).b, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).b, text, count)
            else:
                # XXX: Refactor this whole class. It's getting out of hand.
                if self.view.substr(s.b) == '\n':
                    self.paste_all(edit, s, s.b + offset, text, count)
                else:
                    self.paste_all(edit, s, s.b + offset + 1, text, count)
                offset += len(text) * count
コード例 #5
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)
        register = register or '"'
        fragments = state.registers[register]
        if not fragments:
            print("Vintageous: Nothing in register \".")
            return

        sels = list(self.view.sel())
        # If we have the same number of pastes and selections, map 1:1. Otherwise paste paste[0]
        # to all target selections.
        if len(sels) == len(fragments):
            sel_to_frag_mapped = zip(sels, fragments)
        else:
            sel_to_frag_mapped = zip(sels, [
                fragments[0],
            ] * len(sels))

        # FIXME: Fix this mess. Separate linewise from charwise pasting.
        pasting_linewise = True
        offset = 0
        paste_locations = []
        for selection, fragment in reversed(list(sel_to_frag_mapped)):
            fragment = self.prepare_fragment(fragment)
            if fragment.startswith('\n'):
                # Pasting linewise...
                # If pasting at EOL or BOL, make sure we paste before the newline character.
                if (utils.is_at_eol(self.view, selection)
                        or utils.is_at_bol(self.view, selection)):
                    l = self.paste_all(edit, selection,
                                       self.view.line(selection.b).b, fragment,
                                       count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, selection,
                                       self.view.line(selection.b - 1).b,
                                       fragment, count)
                    paste_locations.append(l)
            else:
                pasting_linewise = False
                # Pasting charwise...
                # If pasting at EOL, make sure we don't paste after the newline character.
                if self.view.substr(selection.b) == '\n':
                    l = self.paste_all(edit, selection, selection.b + offset,
                                       fragment, count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, selection,
                                       selection.b + offset + 1, fragment,
                                       count)
                    paste_locations.append(l)
                offset += len(fragment) * count

        if pasting_linewise:
            self.reset_carets_linewise()
        else:
            self.reset_carets_charwise(paste_locations, len(fragment))
コード例 #6
0
ファイル: transformers_visual.py プロジェクト: gak/Vintageous
        def f(view, s):
            delta = 1
            if mode == MODE_VISUAL:
                delta = 1 if utils.is_region_reversed(view, s) else 2

            text_before_caret = view.substr(sublime.Region(view.line(s.b).a, s.b - delta))
            first_char_is_space = view.substr(s.b - delta).isspace() if (view.line(s.b).a == s.b - delta) else False

            if mode == MODE_NORMAL:
                if text_before_caret.isspace() or first_char_is_space:
                    pt = utils.previous_non_white_space_char(self.view, s.b - 1, white_space='\t ')
                    if view.line(pt).empty():
                        return sublime.Region(s.a , pt + 1)
                    elif view.word(pt).size() == 1:
                        return sublime.Region(pt + 1, pt + 1)

                    return sublime.Region(pt, pt)

                # At BOL.
                # XXX: Use a general function instead of spelling out the computation.
                elif view.line(s.b).a == s.b and not view.line(s.b - 1).empty():
                    return sublime.Region(s.b - 1, s.b - 1)

            elif mode == MODE_VISUAL:
                if utils.is_region_reversed(view, s):

                    if text_before_caret.isspace() or first_char_is_space:
                        pt = utils.previous_non_white_space_char(self.view, s.b - delta, white_space='\t ')
                        # PREVIOUSLINE empty; don't go past it.
                        if view.line(pt).empty():
                            return sublime.Region(s.a , pt + 1)
                        return sublime.Region(s.a, pt)

                    elif utils.is_at_bol(view, s) and not view.line(s.b - 1).empty():
                        # Single-character words are a special case; we don't want to skip over
                        # them.
                        if view.word(s.b - 1).size() > 1:
                            return sublime.Region(s.a, s.b - 1)

                else:
                    # Non-reversed region. Note that .b here is at NEXTCHAR, not CURRENTCHAR.
                    if text_before_caret.isspace() or first_char_is_space:
                        pt = utils.previous_non_white_space_char(self.view, s.b - delta, white_space='\t ')
                        if view.line(pt).empty():
                            return sublime.Region(s.a , pt + 1)
                        # XXX: I don't think this branch is necessary.
                        # On new WORD; make sure motion doesn't skip it.
                        elif view.substr(pt) not in ('\t \n'):
                            return sublime.Region(s.a, pt + 1)

                        return sublime.Region(s.a, pt)

                    # At WORDBEGIN or at any non-ALPHANUMERICCHAR.
                    elif (view.word(s.b - 1).a == s.b - 1) or not view.substr(s.b - 1).isalnum():
                        return sublime.Region(s.a, s.b - 1)

            return s
コード例 #7
0
ファイル: actions.py プロジェクト: ahnan4arch/Vintageous
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)
        register = register or '"'
        fragments = state.registers[register]
        if not fragments:
            print("Vintageous: Nothing in register \".")
            return

        sels = list(self.view.sel())
        # If we have the same number of pastes and selections, map 1:1. Otherwise paste paste[0]
        # to all target selections.
        if len(sels) == len(fragments):
            sel_to_frag_mapped = zip(sels, fragments)
        else:
            sel_to_frag_mapped = zip(sels, [fragments[0],] * len(sels))

        # FIXME: Fix this mess. Separate linewise from charwise pasting.
        pasting_linewise = True
        offset = 0
        paste_locations = []
        for selection, fragment in reversed(list(sel_to_frag_mapped)):
            fragment = self.prepare_fragment(fragment)
            if fragment.startswith('\n'):
                # Pasting linewise...
                # If pasting at EOL or BOL, make sure we paste before the newline character.
                if (utils.is_at_eol(self.view, selection) or
                    utils.is_at_bol(self.view, selection)):
                    l = self.paste_all(edit, selection,
                                       self.view.line(selection.b).b,
                                       fragment,
                                       count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, selection,
                                   self.view.line(selection.b - 1).b,
                                   fragment,
                                   count)
                    paste_locations.append(l)
            else:
                pasting_linewise = False
                # Pasting charwise...
                # If pasting at EOL, make sure we don't paste after the newline character.
                if self.view.substr(selection.b) == '\n':
                    l = self.paste_all(edit, selection, selection.b + offset,
                                   fragment, count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, selection, selection.b + offset + 1,
                                   fragment, count)
                    paste_locations.append(l)
                offset += len(fragment) * count

        if pasting_linewise:
            self.reset_carets_linewise()
        else:
            self.reset_carets_charwise(paste_locations, len(fragment))
コード例 #8
0
        def f(view, s):
            is_last_iteration = (current_iteration == total_iterations - 1)

            if mode == _MODE_INTERNAL_NORMAL:
                # If we're at BOL one LINE down; move to NEXTWORD WORDEND inclusive.
                if utils.is_at_bol(self.view, s):
                    next = utils.next_non_white_space_char(self.view,
                                                           s.b,
                                                           white_space='\t \n')
                    next = self.view.word(next)
                    return sublime.Region(s.a, next.b)
                else:
                    return s

            elif mode == MODE_NORMAL:
                # If we're at BOL one LINE down; move to NEXTWORD WORDEND exclusive.
                if utils.is_at_bol(self.view, s):
                    next = utils.next_non_white_space_char(self.view,
                                                           s.b,
                                                           white_space='\t \n')
                    next = self.view.word(next)
                    return sublime.Region(next.b - 1, next.b - 1)
                # Last motion; ensure caret ends up at a WORDEND exclusive. The native 'move'
                # command will have left us on the next character.
                elif is_last_iteration:
                    return sublime.Region(s.a - 1, s.b - 1)
                else:
                    return s

            elif mode == MODE_VISUAL:
                # If we're at BOL one LINE down, move to NEXTWORD WORDEND inclusive.
                if utils.is_at_bol(self.view, s):
                    next = utils.next_non_white_space_char(self.view,
                                                           s.b,
                                                           white_space='\t \n')
                    next = self.view.word(next)
                    return sublime.Region(s.a, next.b)
                else:
                    return s
コード例 #9
0
ファイル: actions.py プロジェクト: nelk/Vintageous
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if state.mode == MODE_VISUAL:
            # force register population. We have to do it here
            vi_cmd_data = {
                "synthetize_new_line_at_eof": True,
                "yanks_linewise": False,
            }
            prev_text = state.registers.get_selected_text(vi_cmd_data)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']

        if state.mode == MODE_VISUAL:
            # Populate registers with the text we're about to paste.
            state.registers['"'] = prev_text

        sels = list(self.view.sel())
        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        pasting_linewise = True
        offset = 0
        paste_locations = []
        for s, text in sel_frag:
            row = self.view.rowcol(s.begin())[0]
            row = max(0, row - 1)
            if text.endswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    l = self.paste_all(edit, s, self.view.line(s.b).a, text, count)
                    paste_locations.append(l)
                else:
                    l = self.paste_all(edit, s, self.view.line(s.b - 1).a, text, count)
                    paste_locations.append(l)
            else:
                pasting_linewise = False
                l = self.paste_all(edit, s, s.b + offset, text, count)
                paste_locations.append(l)
                offset += len(text) * count

        if pasting_linewise:
            self.reset_carets_linewise()
        else:
            self.reset_carets_charwise(paste_locations, len(text))
コード例 #10
0
ファイル: action_cmds.py プロジェクト: Web5design/Vintageous
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']
            if not fragments:
                print("Vintageous: Nothing in register \".")
                # XXX: This won't ever be printed because it will be overwritten by other status
                # messages printed right after this one.
                sublime.status_message("Vintageous: Nothing in register \".")
                return

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            text = self.prepare_fragment(text)
            if text.startswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).b, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).b, text, count)
            else:
                # XXX: Refactor this whole class. It's getting out of hand.
                if self.view.substr(s.b) == '\n':
                    self.paste_all(edit, s, s.b + offset, text, count)
                else:
                    self.paste_all(edit, s, s.b + offset + 1, text, count)
                offset += len(text) * count
コード例 #11
0
    def run(self, edit, register=None, count=1):
        state = VintageState(self.view)

        if register:
            fragments = state.registers[register]
        else:
            # TODO: There should be a simpler way of getting the unnamed register's content.
            fragments = state.registers['"']
            if not fragments:
                print("Vintageous: Nothing in register \".")
                # XXX: This won't ever be printed because it will be overwritten by other status
                # messages printed right after this one.
                sublime.status_message("Vintageous: Nothing in register \".")
                return

        sels = list(self.view.sel())

        if len(sels) == len(fragments):
            sel_frag = zip(sels, fragments)
        else:
            sel_frag = zip(sels, [fragments[0],] * len(sels))

        offset = 0
        for s, text in sel_frag:
            text = self.prepare_fragment(text)
            if text.startswith('\n'):
                if utils.is_at_eol(self.view, s) or utils.is_at_bol(self.view, s):
                    self.paste_all(edit, s, self.view.line(s.b).b, text, count)
                else:
                    self.paste_all(edit, s, self.view.line(s.b - 1).b, text, count)
            else:
                # XXX: Refactor this whole class. It's getting out of hand.
                if self.view.substr(s.b) == '\n':
                    self.paste_all(edit, s, s.b + offset, text, count)
                else:
                    self.paste_all(edit, s, s.b + offset + 1, text, count)
                offset += len(text) * count