Esempio n. 1
0
def error(vim: Nvim, expr: typing.Any):
    """
    Prints the error messages to Vim/Nvim's :messages buffer.
    """
    if hasattr(vim, 'err_write'):
        string = (expr if isinstance(expr, str) else str(expr))
        return vim.err_write('[defx] ' + string + '\n')
    else:
        vim.call('defx#util#print_error', expr)
Esempio n. 2
0
def cwd_input(vim: Nvim,
              cwd: str,
              prompt: str,
              text: str = '',
              completion: str = '') -> str:
    """
    Returns the absolute input path in cwd.
    """
    save_cwd = vim.call('getcwd')
    vim.command('lcd {}'.format(cwd))

    filename = vim.call('input', prompt, text, completion)
    filename = os.path.normpath(os.path.join(cwd, filename))

    vim.command('lcd {}'.format(save_cwd))
    return filename
Esempio n. 3
0
def cwd_input(vim: Nvim,
              cwd: str,
              prompt: str,
              text: str = '',
              completion: str = '') -> typing.Optional[Path]:
    """
    Returns the absolute input path in cwd.
    """
    save_cwd = vim.call('getcwd')
    vim.command(f'silent lcd {cwd}')

    filename: str = vim.call('input', prompt, text, completion)
    if not filename:
        return None

    vim.command(f'silent lcd {save_cwd}')
    return Path(cwd).joinpath(filename).resolve()
Esempio n. 4
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import os
import argparse
from neovim import socket_session, Nvim

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="NeoVim TeX client")
    parser.add_argument('--addr', default='/tmp/nvim_tex.sock',
                        help="NeoVim listen address")
    parser.add_argument('file', help="file")
    parser.add_argument('line', type=int, help="line")
    args = parser.parse_args()

    session = socket_session(args.addr)
    nvim = Nvim.from_session(session)

    if not os.path.samefile(nvim.current.buffer.name, args.file):
        nvim.command("e {}".format(os.path.normpath(args.file)))

    nvim.current.window.cursor = (args.line, 0)
    nvim.feedkeys("zz")

# vim: ts=4 sts=4 sw=4 expandtab
Esempio n. 5
0
nvim_prog = os.environ.get('NVIM_PROG', 'build/bin/nvim')
nvim_argv = [nvim_prog, '-u', 'NONE', '--embed']

if 'VALGRIND' in os.environ:
    log_file = os.environ.get('VALGRIND_LOG', 'valgrind-%p.log')
    valgrind_argv = [
        'valgrind', '-q', '--tool=memcheck', '--leak-check=yes',
        '--track-origins=yes', '--suppressions=.valgrind.supp',
        '--log-file={0}'.format(log_file)
    ]
    if 'VALGRIND_GDB' in os.environ:
        valgrind_argv += ['--vgdb=yes', '--vgdb-error=0']
    nvim_argv = valgrind_argv + nvim_argv

session = spawn_session(nvim_argv)
nvim = Nvim.from_session(session)


def nvim_command(cmd):
    nvim.command(cmd)


def nvim_eval(expr):
    return to_table(nvim.eval(expr))


def nvim_feed(input, mode=''):
    nvim.feedkeys(input)


def buffer_slice(start=None, stop=None, buffer_idx=None):
Esempio n. 6
0
(2) recompiling Vim against the Python where you already have IPython
installed. This is only a requirement to allow Vim to speak with an IPython
instance using IPython's own machinery. It does *not* mean that the IPython
instance with which you communicate via vim-ipython needs to be running the
same version of Python.
"""

try:
    import IPython
except ImportError:
    raise ImportError("Could not find kernel. " + _install_instructions)

try:
    from neovim import Nvim
    from neovim.msgpack_rpc import stdio_session
    vim = Nvim.from_session(stdio_session())
except ImportError:
    raise ImportError('vim module only available within vim!')

# ------------------------------------------------------------------------------
#        Read global configuration variables
# ------------------------------------------------------------------------------
is_py3 = sys.version_info[0] >= 3
if is_py3:
    unicode = str

prompt_in = 'In [{line:d}]: '
prompt_out = 'Out[{line:d}]: '

# General message command
Esempio n. 7
0
def confirm(vim: Nvim, question: str) -> bool:
    """
    Confirm action
    """
    option: int = vim.call('confirm', question, '&Yes\n&No\n&Cancel')
    return option is 1
Esempio n. 8
0
def error(vim: Nvim, expr: typing.Any) -> None:
    """
    Prints the error messages to Vim/Nvim's :messages buffer.
    """
    vim.call('defx#util#print_error', expr)