Python vim.vars() Examples

The following are 17 code examples of vim.vars(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vim , or try the search function .
Example #1
Source File: roast.py    From roast.vim with MIT License 6 votes vote down vote up
def highlight_line(group, buf_number, line_number):
    match_id = int(vim.buffers[buf_number].vars.get('_roast_match_id', 0))

    if match_id:
        win = None
        for win in vim.windows:
            if win.buffer.number == buf_number:
                break

        try:
            vim.eval(f'matchdelete({match_id})' if win is None else f'matchdelete({match_id}, {win.number})')
        except vim.error:
            # TODO: Only hide E803 error, which is thrown if this match_id has already been deleted.
            pass

    vim.buffers[buf_number].vars['_roast_match_id'] = vim.eval(
        fr"matchadd('{group}', '\V' . escape(getbufline({buf_number}, {line_number + 1})[0], '\') . '\$')"
    ) 
Example #2
Source File: ncm2_jedi.py    From ncm2-jedi with MIT License 6 votes vote down vote up
def __init__(self, vim):
        Ncm2Source.__init__(self, vim)

        env = vim.vars['ncm2_jedi#environment']
        if not env:
            osenv = os.environ
            if 'VIRTUAL_ENV' not in osenv and 'CONDA_PREFIX' in osenv:
                # if conda is active
                self._env = jedi.create_environment(osenv['CONDA_PREFIX'])
            else:
                # get_default_environment handles VIRTUAL_ENV
                self._env = jedi.get_default_environment()
        else:
            self._env = jedi.create_environment(env)

        rc_settings = vim.vars['ncm2_jedi#settings']
        for name in rc_settings:
            setattr(settings, name, rc_settings[name]) 
Example #3
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_get_var(name):
    return vim.vars[name] 
Example #4
Source File: _vim.py    From completor.vim with MIT License 5 votes vote down vote up
def _patch_nvim(vim):
    class Bindeval(object):
        def __init__(self, data):
            self.data = data

        def __getitem__(self, key):
            return _bytes(self.data[key])

    def function(name):
        def inner(*args, **kwargs):
            ret = vim.call(name, *args, **kwargs)
            return _bytes(ret)
        return inner

    def bindeval(value):
        data = vim.eval(value)
        return Bindeval(data)

    vim_vars = vim.vars

    class vars_wrapper(object):
        def get(self, *args, **kwargs):
            item = vim_vars.get(*args, **kwargs)
            return _bytes(item)

    vim.Function = function
    vim.bindeval = bindeval
    vim.List = list
    vim.Dictionary = dict
    vim.vars = vars_wrapper() 
Example #5
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_get_client_info():
    if '_neovim_rpc_client_info' not in vim.vars:
        return []
    return vim.vars['_neovim_rpc_client_info'] 
Example #6
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_set_client_info(*args):
    # https://github.com/roxma/vim-hug-neovim-rpc/issues/61
    vim.vars['_neovim_rpc_client_info'] = args 
Example #7
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_win_set_var(window, name, val):
    window.vars[name] = val 
Example #8
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_buf_set_var(buffer, name, val):
    buffer.vars[name] = val 
Example #9
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_buf_get_var(buffer, name):
    return buffer.vars[name] 
Example #10
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_set_var(name, val):
    vim.vars[name] = val
    return val 
Example #11
Source File: neovim_rpc_methods.py    From vim-hug-neovim-rpc with MIT License 5 votes vote down vote up
def nvim_call_function(method, args):
    vim.vars['_neovim_rpc_tmp_args'] = args
    # vim.eval('getcurpos()') return an array of string, it should be an array
    # of int.  Use json_encode to workaround this
    return vim.bindeval('call("%s",g:_neovim_rpc_tmp_args)' % method) 
Example #12
Source File: test_load.py    From validator.vim with MIT License 5 votes vote down vote up
def test_load_checkers():
    import vim

    with mock.patch.dict(vim.vars, {
            'validator_filetype_map': {b'abcd': b'linter1'}}):
        assert isinstance(load_checkers(b'abcd')['checker1'], Linter1)
    assert isinstance(load_checkers(b'linter2')['checker2'], Linter2) 
Example #13
Source File: test_validator.py    From validator.vim with MIT License 5 votes vote down vote up
def test_args():
    assert NoName().cmd_args == '-a -b -c -d'
    with mock.patch.dict(vim.vars, {'validator_no_name_args': b'-l'}):
        assert NoName().cmd_args == '-l' 
Example #14
Source File: test_validator.py    From validator.vim with MIT License 5 votes vote down vote up
def test_binary():
    assert NoName().binary == 'ls'
    with mock.patch.dict(vim.vars, {'validator_no_name_binary': b'lls'}):
        assert NoName().binary == 'lls' 
Example #15
Source File: roast.py    From roast.vim with MIT License 5 votes vote down vote up
def next_render(delta=1):
    renderer = vim.current.buffer.vars['_roast_renderer']
    if not isinstance(renderer, str):
        renderer = renderer.decode()
    vim.command('buffer __roast_' + renderers[(renderers.index(renderer) + delta) % len(renderers)] + '__') 
Example #16
Source File: roast.py    From roast.vim with MIT License 5 votes vote down vote up
def show_error(message: str):
    vim.vars['__roast_error_message'] = message
    vim.eval("timer_start(10, {_ -> execute(['echohl Error', 'redraw', 'echomsg g:__roast_error_message',"
             " 'echohl None', 'unlet g:__roast_error_message'], '')})") 
Example #17
Source File: roast.py    From roast.vim with MIT License 4 votes vote down vote up
def show_response(response: requests.Response):
    # A window holding a roast buffer, to be used as a workspace for setting up all roast buffers.
    workspace_window = workspace_renderer = None
    for window in vim.windows:
        if '_roast_renderer' in window.buffer.vars:
            workspace_window = window
            workspace_renderer = window.buffer.vars['_roast_renderer']
            if not isinstance(workspace_renderer, str):
                workspace_renderer = workspace_renderer.decode()
            break

    # Switch to workspace window.
    prev_window = vim.current.window

    for renderer in renderers:
        buf_name = f'__roast_{renderer}__'
        num = bufnr(buf_name)
        if num < 0:
            if workspace_window is not None:
                vim.current.window = workspace_window
                vim.command(f'keepalt edit {buf_name} | setl bt=nofile bh=hide noswf nornu')
                num = bufnr(buf_name)
            else:
                vim.command(f'keepalt vnew {buf_name} | setl bt=nofile bh=hide noswf nornu')
                num = bufnr(buf_name)
                vim.current.window = workspace_window = vim.windows[int(vim.eval(f'bufwinnr({num})')) - 1]
        else:
            if workspace_window is not None:
                vim.current.window = workspace_window
                vim.command(f'keepalt {num}buffer')
            else:
                vim.command(f'keepalt vertical {num}sbuffer')
                vim.current.window = workspace_window = vim.windows[int(vim.eval(f'bufwinnr({num})')) - 1]

        buf = vim.buffers[num]
        buf[:] = None

        buf.vars['_roast_renderer'] = renderer
        actions = getattr(roast_api, f'render_{renderer}')(buf, response)
        apply_actions(buf, actions)
        workspace_window.options['statusline'] = "Roast <%{get(b:, '_roast_renderer', 'N/A')}>  " + \
                ('' if response.ok else '%#Error#') + " HTTP:" + str(response.status_code) + " %*  %{&ft}"

    vim.command(f'{workspace_window.number}windo keepalt buffer __roast_{workspace_renderer or renderers[0]}__')
    vim.current.window = prev_window