Example #1
0
def a_word(view, pt, inclusive=True, count=1):
    # type: (...) -> Region
    assert count > 0
    start = current_word_start(view, pt)
    end = pt

    if inclusive:
        end = units.word_starts(view, start, count=count, internal=True)

        # If there is no space at the end of our word text object, include any
        # preceding spaces. (Follows Vim behavior.)
        if (not view.substr(end - 1).isspace()
                and view.substr(start - 1).isspace()):
            start = utils.previous_non_white_space_char(
                view, start - 1, white_space=' \t') + 1

        # Vim does some inconsistent stuff here...
        if count > 1 and view.substr(end) == '\n':
            end += 1

        return Region(start, end)

    for x in range(count):
        end = current_word_end(view, end)

    return Region(start, end)
Example #2
0
def find_sentences_backward(view, start_pt, count=1):
    if isinstance(start_pt, Region):
        start_pt = start_pt.a

    pt = utils.previous_non_white_space_char(view, start_pt, white_space='\n \t')
    sen = Region(pt)
    while True:
        sen = view.expand_by_class(sen, CLASS_LINE_END | CLASS_PUNCTUATION_END)
        if sen.a <= 0 or view.substr(sen.begin() - 1) in ('.', '\n', '?', '!'):
            if view.substr(sen.begin() - 1) == '.' and not view.substr(sen.begin()) == ' ':
                continue

            return sen