Ejemplo n.º 1
0
Archivo: test.py Proyecto: AdaCore/gps
def run_test():
    buf = GPS.EditorBuffer.get(GPS.File("foo.adb"))
    yield wait_tasks(other_than=known_tasks)

    for start, end in expected:
        loc = buf.at(1, start)
        # start => end
        e_loc = text_utils.goto_word_end(loc, underscore_is_word=False)
        # goto_word_end is returning the last column still inside the word
        gps_assert(e_loc.column() + 1, end, "goto_word_end")
        # end => start
        s_loc = text_utils.goto_word_start(e_loc, underscore_is_word=False)
        gps_assert(s_loc.column(), start, "goto_word_start")

    # Edge cases: no infinite loop at start and end of buffer
    text_utils.goto_word_end(buf.end_of_buffer(),
                             underscore_is_word=False)
    text_utils.goto_word_start(buf.beginning_of_buffer(),
                               underscore_is_word=False)
Ejemplo n.º 2
0
    def get_word_bounds(loc):
        loc_id_start = goto_word_start(loc)
        loc_id_end = goto_word_end(loc)
        # Check the case when we are at the end of a word
        if not id_pattern.match(loc.get_char()):
            ploc = loc.forward_char(-1)
            # If we are really not in an identifier, exit
            if not id_pattern.match(ploc.get_char()):
                return None, None
            else:
                loc_id_end = ploc

        return loc_id_start, loc_id_end
Ejemplo n.º 3
0
def find_current_word(context):
    """
    Stores in context the current word start, end and text.
    This is called only when computing whether the menu should be
    displayed, and stored in the contextual menu for efficiency, since
    that means we won't have to recompute the info if the user selects
    the menu.
    """

    buffer = GPS.EditorBuffer.get()
    view = buffer.current_view()
    cursor = view.cursor()

    start = goto_word_start(cursor, underscore_is_word=False)
    cursor = goto_word_end(cursor, underscore_is_word=False)

    context.ispell_module_start = start
    context.ispell_module_end = cursor
    context.ispell_module_word = buffer.get_chars(start, cursor)
Ejemplo n.º 4
0
def expand_alias_action():
    """
    Action to expand the alias under cursor
    the editor
    """
    editor = EditorBuffer.get(open=False, force=False)
    if not editor:
        return

    if is_in_alias_expansion(editor):
        return
    with editor.new_undo_group():
        cursor_loc = editor.current_view().cursor().forward_char(-1)
        start_loc = goto_word_start(cursor_loc)
        alias_name = editor.get_chars(start_loc, cursor_loc)
        editor.delete(start_loc, cursor_loc)
        alias = Alias.get(alias_name)
        if alias:
            expand_alias(editor, alias)
Ejemplo n.º 5
0
def expand_alias_action():
    """
    Action to expand the alias under cursor
    the editor
    """
    editor = EditorBuffer.get(open=False, force=False)
    if not editor:
        return

    if is_in_alias_expansion(editor):
        return
    with editor.new_undo_group():
        cursor_loc = editor.current_view().cursor().forward_char(-1)
        start_loc = goto_word_start(cursor_loc)
        alias_name = editor.get_chars(start_loc, cursor_loc)
        editor.delete(start_loc, cursor_loc)
        alias = Alias.get(alias_name)
        if alias:
            expand_alias(editor, alias)