示例#1
0
def rename(clang_service):
    clang_service.update_buffers(__get_bufctx_list())
    clang_service.parse_all(vim.eval('g:clighter_compile_args'))

    cc = clang_service.get_cc(vim.current.buffer.name)
    if not cc:
        return

    tu = cc.current_tu
    if not tu:
        return

    symbol = clighter_helper.get_vim_symbol(
        clighter_helper.get_vim_cursor(tu, tu.get_file(cc.name)))

    if not symbol:
        return

    old_name = clighter_helper.get_spelling_or_displayname(symbol)
    vim.command("echohl WildMenu")
    new_name = vim.eval(
        "input(' Rename {0} : ', '{1}')".format(old_name, old_name))
    vim.command("echohl None")

    if not new_name or old_name == new_name:
        return

    print ' '

    pos = vim.current.window.cursor

    locs = set()
    locs.add((symbol.location.line, symbol.location.column,
              symbol.location.file.name))
    clighter_helper.search_referenced_tokens(
        tu,
        symbol,
        locs)

    prompt = string.atoi(vim.eval('g:clighter_rename_prompt_level'))

    __vim_multi_replace(
        locs,
        old_name,
        new_name,
        prompt)

    if clighter_helper.is_global_symbol(
            symbol) and vim.eval('g:clighter_enable_cross_rename') == '1':
        __cross_buffer_rename(
            clang_service,
            symbol.get_usr(),
            new_name,
            prompt)

    vim.current.window.cursor = pos

    clang_service.update_buffers(__get_bufctx_list())
    clang_service.switch(vim.current.buffer.name)           
示例#2
0
def hl_window(clang_service, do_occurrences):
    cc = clang_service.get_cc(vim.current.buffer.name)
    if not cc:
        return

    parse_tick = cc.parse_tick

    tu = cc.current_tu
    if not tu:
        return

    top = string.atoi(vim.eval("line('w0')"))
    bottom = string.atoi(vim.eval("line('w$')"))
    height = bottom - top + 1

    symbol = None

    if vim.eval('g:ClighterOccurrences') == '1':
        vim_cursor = clighter_helper.get_vim_cursor(tu)
        symbol = clighter_helper.get_vim_symbol(vim_cursor)

    occurrences_range = w_range = [top, bottom]
    syntax_range = [max(top - height, 1), min(
        bottom + height, len(vim.current.buffer))]

    config_win_context(False)

    if vim.current.window.vars['clighter_hl'][0] < parse_tick:
        clear_all()
    else:
        if not __is_subrange(
            w_range, list(
                vim.current.window.vars['clighter_hl'][1])):
            __vim_clear_match_pri(SYNTAX_PRI)
        else:
            syntax_range = None

        if not __is_subrange(
            w_range, list(
                vim.current.window.vars['clighter_hl'][2])) or (
            hl_window.symbol and (
                not symbol or symbol != hl_window.symbol)):
            clear_occurrences()
        else:
            occurrences_range = None

    if not do_occurrences:
        occurrences_range = None

    hl_window.symbol = symbol

    __do_highlight(
        tu,
        vim.current.buffer.name,
        syntax_range,
        occurrences_range,
        parse_tick)
示例#3
0
def hl_window(clang_service, do_symbol_hl):
    cc = clang_service.get_cc(vim.current.buffer.name)
    if cc is None:
        return

    parse_tick = cc.parse_tick

    tu = cc.current_tu
    if tu is None:
        return

    file = tu.get_file(cc.name)

    top = string.atoi(vim.eval("line('w0')"))
    bottom = string.atoi(vim.eval("line('w$')"))
    height = bottom - top + 1

    symbol = None

    if vim.eval('g:ClighterCursorHL') == '1':
        vim_cursor = clighter_helper.get_vim_cursor(tu, file)
        symbol = clighter_helper.get_vim_symbol(vim_cursor)

    w_range = [top, bottom]
    syntax_range = [
        max(top - height, 1),
        min(bottom + height, len(vim.current.buffer))
    ]
    symbol_range = w_range

    if vim.current.window.vars['hl_tick'] < parse_tick:
        clear_highlight()
    else:
        if not __is_contained_in(w_range, hl_window.syntax_range):
            __vim_clear_match_pri(SYNTAX_PRI)
        else:
            syntax_range = None

        if not __is_contained_in(w_range, hl_window.symbol_range) or (
                hl_window.symbol and
            (not symbol or symbol != hl_window.symbol)):
            clear_symbol_hl()
        else:
            symbol_range = None

    if not do_symbol_hl:
        symbol_range = None

    __do_highlight(tu, file, syntax_range, symbol, symbol_range)
    vim.current.window.vars['hl_tick'] = parse_tick
示例#4
0
def rename(clang_service):
    clang_service.update_buffers(__get_bufctx_list(), False)
    clang_service.parse_all(
        string.atoi(vim.eval('g:clighter_heuristic_compile_args')),
        vim.bindeval('g:clighter_compile_args'))

    cc = clang_service.get_cc(vim.current.buffer.name)
    if not cc:
        return

    tu = cc.current_tu
    if not tu:
        return

    symbol = clighter_helper.get_vim_symbol(
        clighter_helper.get_vim_cursor(tu, tu.get_file(cc.name)))

    if not symbol:
        return

    old_name = clighter_helper.get_spelling_or_displayname(symbol)
    vim.command("echohl WildMenu")
    new_name = vim.eval("input(' Rename {0} : ', '{1}')".format(
        old_name, old_name))
    vim.command("echohl None")

    if not new_name or old_name == new_name:
        return

    print ' '

    pos = vim.current.window.cursor

    locs = set()
    locs.add((symbol.location.line, symbol.location.column,
              symbol.location.file.name))
    clighter_helper.search_referenced_tokens(tu, symbol, locs)

    prompt = string.atoi(vim.eval('g:clighter_rename_prompt_level'))

    __vim_multi_replace(locs, old_name, new_name, prompt)

    if clighter_helper.is_global_symbol(symbol) and vim.eval(
            'g:clighter_enable_cross_rename') == '1':
        __cross_buffer_rename(clang_service, symbol.get_usr(), new_name,
                              prompt)

    vim.current.window.cursor = pos

    clang_service.update_buffers(__get_bufctx_list(), True)
示例#5
0
def hl_window(clang_service, do_symbol_hl):
    cc = clang_service.get_cc(vim.current.buffer.name)
    if cc is None:
        return

    parse_tick = cc.parse_tick

    tu = cc.current_tu
    if tu is None:
        return

    file = tu.get_file(cc.name)

    top = string.atoi(vim.eval("line('w0')"))
    bottom = string.atoi(vim.eval("line('w$')"))
    height = bottom - top + 1

    symbol = None

    if vim.eval('g:ClighterCursorHL') == '1':
        vim_cursor = clighter_helper.get_vim_cursor(tu, file)
        symbol = clighter_helper.get_vim_symbol(vim_cursor)

    w_range = [top, bottom]
    syntax_range = [max(top - height, 1), min(
        bottom + height, len(vim.current.buffer))]
    symbol_range = w_range

    if vim.current.window.vars['hl_tick'] < parse_tick:
        clear_highlight()
    else:
        if not __is_contained_in(w_range, hl_window.syntax_range):
            __vim_clear_match_pri(SYNTAX_PRI)
        else:
            syntax_range = None

        if not __is_contained_in(w_range, hl_window.symbol_range) or (hl_window.symbol and (not symbol or symbol != hl_window.symbol)):
            clear_symbol_hl()
        else:
            symbol_range = None

    if not do_symbol_hl:
        symbol_range = None

    __do_highlight(tu, file, syntax_range, symbol, symbol_range)
    vim.current.window.vars['hl_tick'] = parse_tick