-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_in_nvim.py
executable file
·33 lines (33 loc) · 1.06 KB
/
load_in_nvim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
"""Edit a file in the host nvim instance."""
from __future__ import print_function
import os
import sys
from neovim import attach
args = [os.path.abspath(f) for f in sys.argv[1:]]
if not args:
print("Usage: {} <filename> ...".format(sys.argv[0]))
sys.exit(1)
addr = os.environ.get("NVIM_LISTEN_ADDRESS", None)
if not addr:
os.execvp('nvim', args)
nvim = attach("socket", path=addr)
def _setup():
nvim.input('<c-\\><c-n>') # exit terminal mode
chid = nvim.channel_id
nvim.command('call DWM_New()')
nvim.command('augroup EDIT')
nvim.command('au BufEnter <buffer> call rpcnotify({0}, "n")'.format(chid))
nvim.command('au BufEnter <buffer> startinsert'.format(chid))
nvim.command('augroup END')
nvim.vars['files_to_edit'] = args
for x in args:
nvim.command('exe "drop ".remove(g:files_to_edit, 0)')
def _exit(*args):
nvim.vars['files_to_edit'] = None
nvim.command('augroup EDIT')
nvim.command('au!')
nvim.command('augroup END')
nvim.stop_loop()
# nvim.run_loop(_exit, _exit, _setup)
_setup()