本文整理汇总了Python中neovim.attach函数的典型用法代码示例。如果您正苦于以下问题:Python attach函数的具体用法?Python attach怎么用?Python attach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attach函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, args):
self.args = args
try:
if args["--debug"]:
nvim_launcher_thread = threading.Thread(target=self.__call_nvim__) #Launch nvim in new thread so that V doesn't hang
nvim_launcher_thread.start()
time.sleep(1)
socket = os_code.get_socket_path(args)
try:
self.nvim_instance = neovim.attach("socket", path=socket)
except py33_exceptions.FileNotFoundError:
sys.stderr.write("Couldn't connect to nvim. Did you export your NVIM_LIST_ADDRESS?\n\n")
sys.exit()
else:
args = os_code.get_embedded_nvim_args(args)
try:
self.nvim_instance = neovim.attach("child", argv=args)
except py33_exceptions.FileNotFoundError:
sys.stderr.write("Couldn't find the neovim executable! Is nvim in your $PATH?\n\n")
sys.exit()
except IOError:
sys.stderr.write("Couldn't find the neovim executable! Is neovim installed?\n\n")
sys.exit()
if self.args["--safe"]:
self.nvim_instance.command("source nvim/safe_mode.vim")
self.input_mappings = {'\n' : '\r', '<': "<lt>"}
示例2: __init__
def __init__(self, args):
self.args = args
if args["-d"]:
nvim_launcher_thread = threading.Thread(target=self.__call_nvim__) #Launch nvim in new thread so that V doesn't hang
nvim_launcher_thread.start()
time.sleep(1)
socket = os_code.get_socket_path(args)
try:
self.nvim_instance = neovim.attach("socket", path=socket)
except py33_exceptions.FileNotFoundError:
sys.stderr.write("Couldn't connect to nvim. Did you export your NVIM_LIST_ADDRESS?\n\n")
sys.exit()
else:
args = os_code.get_embedded_nvim_args(args)
try:
self.nvim_instance = neovim.attach("child", argv=args)
except py33_exceptions.FileNotFoundError:
sys.stderr.write("Couldn't find the neovim executable! Is nvim in your $PATH?\n\n")
sys.exit()
if self.args["--safe"]:
self.nvim_instance.command("source nvim/safe_mode.vim")
self.active_reg = "a"
self.pending_number = ""
self.pending_command = ""
self.loop_symbol = ""
self.loop_num = ""
self.recorded_text = ""
self.recording = False
self.keys_sent = []
示例3: setup_neovim
def setup_neovim(serveraddr):
logger.info("connecting to neovim server: %s",serveraddr)
# create another connection to avoid synchronization issue?
if len(serveraddr.split(':'))==2:
serveraddr,port = serveraddr.split(':')
port = int(port)
nvim = attach('tcp',address=serveraddr,port=port)
else:
nvim = attach('socket',path=serveraddr)
sync_rtp(nvim)
return nvim
示例4: main
def main(ctx, prog, notify, listen, connect, profile):
"""Entry point."""
address = connect or listen
if address:
import re
p = re.compile(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\:\d{1,5})?$')
if p.match(address):
args = ('tcp',)
kwargs = {'address': address}
else:
args = ('socket',)
kwargs = {'path': address}
if connect:
# connect to existing instance listening on address
nvim = attach(*args, **kwargs)
elif listen:
# spawn detached instance listening on address and connect to it
import os
import time
from subprocess import Popen
os.environ['NVIM_LISTEN_ADDRESS'] = address
nvim_argv = shlex.split(prog or 'nvim --headless') + ctx.args
# spawn the nvim with stdio redirected to /dev/null.
dnull = open(os.devnull)
p = Popen(nvim_argv, stdin=dnull, stdout=dnull, stderr=dnull)
dnull.close()
while p.poll() or p.returncode is None:
try:
nvim = attach(*args, **kwargs)
break
except IOError:
# socket not ready yet
time.sleep(0.050)
else:
# spawn embedded instance
nvim_argv = shlex.split(prog or 'nvim --embed') + ctx.args
nvim = attach('child', argv=nvim_argv)
if IS_PYTHON3:
nvim = nvim.with_hook(DecodeHook())
from gtk_ui import GtkUI
ui = GtkUI()
bridge = UIBridge()
bridge.connect(nvim, ui, profile if profile != 'disable' else None, notify)
示例5: __init__
def __init__(self):
super(EvinceSyncSourceNeovim, self).__init__()
logging.debug("importing neovim module")
import neovim
logging.debug("attaching to neovim through stdio")
self.nvim = neovim.attach("stdio")
示例6: call_neovim
def call_neovim(editor, editor_flags, files, nvim_socket_path='/tmp'):
"""Call Neovim with a desired number of flags and files.
This is done in a separate function as neovim has a VERY different way of doing things.
If a running Neovim server associated with the current Tmux window is found, then the files are opened there.
Otherwise, a new Neovim instance is created in the pane where the call to this program was made, with the name in a format that this script knows to recognise.
Args:
editor (str): The editor command that should be called.
editor_flags (str): A list of strings containing extra flags that should be called alongside the editor of choice.
files (str): A list of strings containing the files that should be opened.
nvim_socket_path (str): The path where socket files should be stored.
"""
# all running Neovim instances associated with this script follow the format "/tmp/[email protected]", where n is the number of the associated tmux window.
tmux_current_window = subprocess.check_output(["tmux", "display-message", "-p", "#{window_id}"]).rstrip()
socket_path = os.path.join(nvim_socket_path, ''.join(['.nvim-', tmux_current_window.strip().decode('utf-8'), '.omni']))
if os.path.exists(socket_path):
# socket already associated with this window.
# so just attach to it and send the commands
nvim = attach('socket', path=socket_path)
for file in files:
nvim.command('e ' + os.path.join(os.path.abspath(os.curdir), file))
else:
# no associated socket. So we create a new Neovim instance following the format specified above.
command = ['NVIM_LISTEN_ADDRESS=' + socket_path, editor] + editor_flags + files
# the call needs to be run through tmux_send_keys so that tmux recognises that Vim is currently running. This allows vim-tmux-navigator to not break.
tmux_send_keys(command)
示例7: main
def main(ctx, address, send, expr, tab, silent):
if IP_ADDR.match(address):
args = ('tcp',)
kwargs = {'address': address}
else:
args = ('socket',)
kwargs = {'path': address}
try:
nvim = attach(*args, **kwargs)
except Exception as e:
if not silent:
print >> sys.stderr, e.message
sys.exit(1)
if send:
nvim.input(send)
elif expr:
print nvim.eval(expr)
else:
files = ctx.args
if not files:
print >> sys.stderr, 'Need at least one file to edit'
sys.exit(1)
cmd = 'tabedit' if tab else 'edit'
for f in files:
nvim.command('{0} {1}'.format(cmd, f))
示例8: setup
def setup(self):
ribosome.in_vim = False
super().setup()
self.logfile = temp_dir('log') / 'proteome_spec'
self.vimlog = temp_dir('log') / 'vim'
self.logfile.touch()
amino.logging.logfile = self.logfile
amino.logging.amino_file_logging(handler_level=logging.WARN)
argv = ['nvim', '--embed', '-V{}'.format(self.vimlog), '-u', 'NONE']
self.neovim = neovim.attach('child', argv=argv)
NvimFacade.async = _mock_async
NvimFacade.main_event_loop = _nop_main_loop
NvimFacade.proxy = property(_mock_proxy)
NvimFacade.clean = lambda self: True
self.proteome = ProteomeNvimPlugin(self.neovim)
self.vim = self.proteome.vim
self.vim.vars.set_p('config_path', str(self.config))
self.vim.vars.set_p('base_dirs', List(str(self.base)))
self.vim.vars.set_p('type_base_dirs', self.type_bases.keymap(str))
self.vim.vars.set_p('history_base', str(self.history_base))
self.vim.vars.set_p('plugins', List('proteome.plugins.history',
'proteome.plugins.ctags',
'proteome.plugins.config',
'proteome.plugins.unite',
))
self.pros = self.add_projects(
('python', 'pro1'), ('python', 'pro2'), ('vim', 'pro3'))
示例9: populate_windows
def populate_windows(self, client_path):
cname = self.get_client_name(client_path + "/")
nvim = neovim.attach("socket", path=cname)
for win in nvim.windows:
self.wd += 1
win_path = join(client_path, "windows", str(self.wd))
self.init_window(win_path, win)
示例10: populate_buffers
def populate_buffers(self, client_path):
cname = self.get_client_name(client_path + "/")
nvim = neovim.attach("socket", path=cname)
for buf in nvim.buffers:
if isfile(buf.name):
buf_path = join(client_path, "buffers", str(buf.number))
self.init_buffer(buf, buf_path)
示例11: call_neovim
def call_neovim(editor, editor_flags, files, nvim_socket_path='/tmp'):
"""Call Neovim with a desired number of flags and files.
This is in a separate function as neovim has a VERY different way of doing things.
If a Neovim server is running on this Tmux window, then the files are opened there.
Else, create a new Neovim instance in the pane.
Args:
editor (str): The editor command that should be called.
editor_flags (str): A list of strings containing extra flags.
files (str): A list of strings containing the files that should be opened.
nvim_socket_path (str): The path where socket files should be stored. """
# Neovim instances in this script are formattted "/tmp/[email protected]"
win = subprocess.check_output(["tmux", "display-message", "-p", "#{window_id}"])
win = win.rstrip().strip().decode('utf-8')
#socket_path = os.path.join(nvim_socket_path, ''.join(['nvim_omni']))
socket_path = os.environ.get("NVIM_LISTEN_ADDRESS")
if os.path.exists(socket_path):
# socket already associated with this window.
# so just attach to it and send the commands
nvim = attach('socket', path=socket_path)
for file in files:
nvim.command('e ' + os.path.join(os.path.abspath(os.curdir), file))
else:
# no associated socket. So we create a new Neovim instance
command = [editor] + editor_flags + files
# run tmux_send_keys, tmux recognises Vim is running, vim-tmux-navigator not break
tmux_send_keys(command)
示例12: main
def main(files=[]):
neovim = attach('socket', path=os.environ['NVIM_LISTEN_ADDRESS'])
for file in files:
neovim.command('tabedit {}'.format(
os.path.abspath(file)
))
示例13: write
def write(self, path, data, offset=0, fh=None):
r_len = len(data)
cname = self.get_client_name(path)
if cname:
nvim = neovim.attach("socket", path=cname)
lines = data.decode(errors="ignore").splitlines()
if re.match('/clients/\d+/cmd', path):
for c in lines:
nvim.command(c)
elif re.match('/clients/\d+/eval', path):
data = self.nvim_eval(nvim, lines)
elif re.match('/clients/\d+/buffers/new', path):
for f in lines:
nvim.command('drop ' + f)
# initialize the buffer tree
bufnr = str(nvim.eval('bufnr("%")'))
buf_path = join(re.match('/clients/\d+/buffers/', path).group(), bufnr)
self.init_buffer(OBuffer(f.encode()), buf_path)
elif re.match('/clients/\d+/windows/new', path):
for w in lines:
if re.match('((vertical|leftabove|aboveleft|rightbelow|belowright|topleft|botright)\s)*'\
'v?(split|new)', w):
nvim.command(w)
else:
if re.match('/clients/new', path):
self.init_client(data.decode())
# save the data
# TODO: respect file permissions
self.data[path] = self.data[path][:offset] + data
self.files[path]['st_size'] = len(self.data[path])
return r_len
示例14: main
def main(address=None):
if address:
nvim = attach('socket', path=address)
else:
try:
address = sys.argv[1]
nvim = attach('socket', path=address)
except:
nvim_binary = find_executable('nvim')
args = [nvim_binary, '--embed']
# args.extend(['-u', 'NONE'])
nvim = attach('child', argv=args)
ui = NvimFriendly()
bridge = UIBridge()
bridge.connect(nvim, ui)
if len(sys.argv) > 1:
nvim.command('edit ' + sys.argv[1])
示例15: attach_vim
def attach_vim(serveraddr):
if len(serveraddr.split(':')) == 2:
serveraddr, port = serveraddr.split(':')
port = int(port)
vim = attach('tcp', address=serveraddr, port=port)
else:
vim = attach('socket', path=serveraddr)
# sync path
for path in vim.call(
'globpath', vim.options['runtimepath'],
'rplugin/python3', 1).split('\n'):
sys.path.append(path)
# Remove current path
del sys.path[0]
return vim