本文整理汇总了Python中neovim.attach函数的典型用法代码示例。如果您正苦于以下问题:Python attach函数的具体用法?Python attach怎么用?Python attach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attach函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>"}
开发者ID:DJMcMayhem,项目名称:V,代码行数:31,代码来源:v.py
示例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 = []
开发者ID:DJMcMayhem,项目名称:vim,代码行数:34,代码来源:v.py
示例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
开发者ID:chaosbaby,项目名称:nvim-completion-manager,代码行数:13,代码来源:cm.py
示例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)
开发者ID:timeyyy,项目名称:python-client,代码行数:48,代码来源:cli.py
示例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")
开发者ID:peder2tm,项目名称:sved,代码行数:7,代码来源:evinceSync.py
示例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)
开发者ID:tonywoode,项目名称:tmux-omnivim,代码行数:31,代码来源:omnivim.py
示例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))
开发者ID:mcordell,项目名称:dotfiles,代码行数:26,代码来源:remote-expr.py
示例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'))
开发者ID:tek,项目名称:proteome,代码行数:27,代码来源:plugin_spec.py
示例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)
开发者ID:expipiplus1,项目名称:nvimfs,代码行数:7,代码来源:fs.py
示例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)
开发者ID:expipiplus1,项目名称:nvimfs,代码行数:7,代码来源:fs.py
示例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)
开发者ID:tulanthoar,项目名称:prezto,代码行数:31,代码来源:omnivim.py
示例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)
))
开发者ID:huhoo,项目名称:vimfiles-1,代码行数:7,代码来源:nvim-tabedit.py
示例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
开发者ID:expipiplus1,项目名称:nvimfs,代码行数:31,代码来源:fs.py
示例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])
开发者ID:ryanmorillo,项目名称:pytknvim,代码行数:17,代码来源:tk_ui.py
示例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
开发者ID:Elv13,项目名称:Config_Files,代码行数:17,代码来源:dp_main.py
示例16: _start_neovim
def _start_neovim(self):
''' start an embedded vim session that loads no init.vim.
**self.vimlog** is set as log file. aside from being convenient,
this is crucially necessary, as the first use of the session
will block if stdout is used for output.
'''
argv = ['nvim', '--embed', '-V{}'.format(self.vimlog), '-u', 'NONE']
self.neovim = neovim.attach('child', argv=argv)
self.vim = self._nvim_facade(self.neovim)
开发者ID:tek,项目名称:tryp-nvim,代码行数:9,代码来源:integration.py
示例17: Start
def Start(self):
"""Starts Neovim"""
self.process = subprocess.Popen(self.start_command, env=self.env)
start_time = time.time()
# Wait at most 5s for the Neovim socket
while not os.path.exists(self.args.servername) \
and time.time() - start_time < 5:
time.sleep(0.01)
self.nvim = neovim.attach('socket', path=self.args.servername)
开发者ID:google,项目名称:vroom,代码行数:9,代码来源:neovim_mod.py
示例18: start
def start():
import neovim
vim = neovim.attach('socket', path='/tmp/v')
input_queue = Queue.Queue()
output_queue = Queue.Queue()
project_dir = os.path.abspath(os.path.curdir)
client = SocketClientThread(vim, input_queue, output_queue, project_dir)
client.start()
开发者ID:vpetro,项目名称:pensive,代码行数:9,代码来源:__init__.py
示例19: run
def run(self):
self.nvim = attach('socket', path=self.path)
cindex.Config.set_library_file(self.nvim.vars['opvim_libclang_path'])
self.is_running = True
while (self.is_running):
event = self.nvim.next_message()
if not event:
continue
开发者ID:osom8979,项目名称:opm,代码行数:9,代码来源:clangserver.py
示例20: attach_socket
def attach_socket(path=None):
'''does it auto'''
def open_nvim():
proc = Popen('NVIM_LISTEN_ADDRESS=/tmp/nvim nvim',
stdin=PIPE, stdout=PIPE, shell=True)
proc.communicate()
# THIS IS DOESNT WORK UNRELIBALE
#path = os.environ.get('NVIM_LISTEN_ADDRESS')
if not path:
print('threading')
t = Thread(target=open_nvim)
t.start()
#todo make this give a random path
return attach('socket', path='/tmp/nvim')
else:
print('attaching socket')
return attach('socket', path=path)
开发者ID:gitter-badger,项目名称:pytknvim,代码行数:18,代码来源:util.py
注:本文中的neovim.attach函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论