Compare commits

...

3 Commits

Author SHA1 Message Date
Marco Hinz 03ad512710
Avoid str.format() if possible 2 years ago
Marco Hinz 842a22a479
Doc: $NVIM_LISTEN_ADDRESS is obsolete in nvim
The server should be started with `nvim --listen /tmp/nvimsocket` or just `nvr`.

When used as client, nvr still supports $NVIM_LISTEN_ADDRESS for backward
compatibility.
2 years ago
Marco Hinz 39e380dec9
Support $NVIM
Latest Neovim from the repo does a few changes to how $NVIM_LISTEN_ADDRESS is
handled. You can still use it to set a servername, but it's not passed on to
children of the process. That also affects the use of :terminal, which will now
have a $NVIM set instead. $NVIM points to the server exactly like
$NVIM_LISTEN_ADDRESS did.

So all that changes, is that we now also check for $NVIM before
$NVIM_LISTEN_ADDRESS.

References https://github.com/neovim/neovim/pull/11009
2 years ago

@ -31,12 +31,12 @@ If you encounter any issues, e.g. permission denied errors or you can't find the
## Theory ## Theory
Nvim always starts a server. Get its address via `:echo $NVIM_LISTEN_ADDRESS` or **Nvim** always starts a server. Get its address with `:echo v:servername`. Or
`:echo v:servername`. Or specify an address at startup: specify an address at startup: `nvim --listen /tmp/nvimsocket`.
`NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim`.
**nvr** will use `$NVIM_LISTEN_ADDRESS` or any address given to it via **nvr** (the client) will use any address given to it via `--servername`,
`--servername`. `$NVIM_LISTEN_ADDRESS` (obsolete in nvim but still supported in nvr), or
defaults to `/tmp/nvimsocket`.
If the targeted address does not exist, **nvr** starts a new process by running If the targeted address does not exist, **nvr** starts a new process by running
"nvim". You can change the command by setting `$NVR_CMD`. _(This requires "nvim". You can change the command by setting `$NVR_CMD`. _(This requires
@ -46,7 +46,7 @@ forking, so it won't work on Windows.)_
Start a nvim process (which acts as a server) in one shell: Start a nvim process (which acts as a server) in one shell:
NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim nvim --listen /tmp/nvimsocket
And do this in another shell: And do this in another shell:
@ -155,18 +155,19 @@ Happy hacking!
Easy-peasy! Just `nvr file`. Easy-peasy! Just `nvr file`.
This works without any prior setup, because `$NVIM_LISTEN_ADDRESS` is always This works without any prior setup, because `$NVIM` is always set for all
set within Nvim. And `nvr` will default to that address. children of the nvim process, including `:terminal`, and `nvr` will default
to that address.
I often work with two windows next to each other. If one contains the I often work with two windows next to each other. If one contains the
terminal, I can use `nvr -l foo` to open the file in the other window. terminal, I can use `nvr -l foo` to open the file in the other window.
- **Open files always in the same nvim process no matter which terminal you're in.** - **Open files always in the same nvim process no matter which terminal you're in.**
If you just run `nvr -s`, a new nvim process will start and set its address Just `nvr -s` starts a new nvim process with the server address set to
to `/tmp/nvimsocket` automatically. `/tmp/nvimsocket`.
Now, no matter in which terminal you are, `nvr file` will always work on Now, no matter which terminal you are in, `nvr file` will always work on
that nvim process. That is akin to `emacsclient` from Emacs. that nvim process. That is akin to `emacsclient` from Emacs.
- **Use nvr in plugins.** - **Use nvr in plugins.**

@ -62,8 +62,7 @@ class Nvr():
self.started_new_process = True self.started_new_process = True
return main2(nvr, options, arguments) return main2(nvr, options, arguments)
time.sleep(0.2) time.sleep(0.2)
print('[!] Unable to attach to the new nvim process. Is `{}` working?' print(f'[!] Unable to attach to the new nvim process. Is `{" ".join(args)}` working?')
.format(" ".join(args)))
sys.exit(1) sys.exit(1)
def execute_new_nvim_process(self, silent, nvr, options, arguments): def execute_new_nvim_process(self, silent, nvr, options, arguments):
@ -83,7 +82,7 @@ class Nvr():
try: try:
os.execvpe(args[0], args, os.environ) os.execvpe(args[0], args, os.environ)
except FileNotFoundError: except FileNotFoundError:
print("[!] Can't start new nvim process: '{}' is not in $PATH.".format(args[0])) print(f'[!] Can\'t start new nvim process: `{args[0]}` is not in $PATH.')
sys.exit(1) sys.exit(1)
def read_stdin_into_buffer(self, cmd): def read_stdin_into_buffer(self, cmd):
@ -98,7 +97,7 @@ class Nvr():
path = self.server.funcs.fnameescape(path) path = self.server.funcs.fnameescape(path)
shortmess = self.server.options['shortmess'] shortmess = self.server.options['shortmess']
self.server.options['shortmess'] = shortmess.replace('F', '') self.server.options['shortmess'] = shortmess.replace('F', '')
self.server.command('{} {}'.format(cmd, path)) self.server.command(f'{cmd} {path}')
self.server.options['shortmess'] = shortmess self.server.options['shortmess'] = shortmess
def diffthis(self): def diffthis(self):
@ -112,8 +111,8 @@ class Nvr():
chanid = self.server.channel_id chanid = self.server.channel_id
self.server.command('augroup nvr') self.server.command('augroup nvr')
self.server.command('autocmd BufDelete <buffer> silent! call rpcnotify({}, "BufDelete")'.format(chanid)) self.server.command(f'autocmd BufDelete <buffer> silent! call rpcnotify({chanid}, "BufDelete")')
self.server.command('autocmd VimLeave * if exists("v:exiting") && v:exiting > 0 | silent! call rpcnotify({}, "Exit", v:exiting) | endif'.format(chanid)) self.server.command(f'autocmd VimLeave * if exists("v:exiting") && v:exiting > 0 | silent! call rpcnotify({chanid}, "Exit", v:exiting) | endif')
self.server.command('augroup END') self.server.command('augroup END')
if 'nvr' in bvars: if 'nvr' in bvars:
@ -178,7 +177,7 @@ def is_netrw_protocol(path):
def parse_args(argv): def parse_args(argv):
form_class = argparse.RawDescriptionHelpFormatter form_class = argparse.RawDescriptionHelpFormatter
usage = '{} [arguments]'.format(argv[0]) usage = argv[0] + ' [arguments]'
epilog = 'Development: https://github.com/mhinz/neovim-remote\n\nHappy hacking!' epilog = 'Development: https://github.com/mhinz/neovim-remote\n\nHappy hacking!'
desc = textwrap.dedent(""" desc = textwrap.dedent("""
Remote control Neovim processes. Remote control Neovim processes.
@ -309,36 +308,40 @@ def parse_args(argv):
def show_message(address): def show_message(address):
print(textwrap.dedent(''' print(textwrap.dedent(f'''
[!] Can't connect to: {} [!] Can't connect to: {address}
The server (nvim) and client (nvr) have to use the same address. The server (nvim) and client (nvr) have to use the same address.
Server: Server:
Expose $NVIM_LISTEN_ADDRESS to the environment before Specify the server address when starting nvim:
starting nvim:
$ NVIM_LISTEN_ADDRESS={} nvim $ nvim --listen {address}
Use `:echo v:servername` to verify the address. Use `:echo v:servername` to verify the address.
Security: When using Unix domain sockets on a multi-user system, Alternatively, run nvr without arguments. It defaults to
the socket should have proper permissions so that it is only starting a new nvim process with the server name set to
accessible by your user. "/tmp/nvimsocket".
Security: When using an Unix domain socket, that socket should
have proper permissions so that it is only accessible by your
user.
Client: Client:
Expose $NVIM_LISTEN_ADDRESS to the environment before Expose $NVIM_LISTEN_ADDRESS (obsolete in nvim but still
using nvr or use its --servername option. If neither supported by nvr) to the environment before using nvr or use
is given, nvr assumes \"/tmp/nvimsocket\". its --servername option. If neither is given, nvr assumes
\"/tmp/nvimsocket\".
$ NVIM_LISTEN_ADDRESS={} nvr file1 file2 $ NVIM_LISTEN_ADDRESS={address} nvr file1 file2
$ nvr --servername {} file1 file2 $ nvr --servername {address} file1 file2
$ nvr --servername 127.0.0.1:6789 file1 file2 $ nvr --servername 127.0.0.1:6789 file1 file2
Use -s to suppress this message. Use -s to suppress this message.
'''.format(address, address, address, address))) '''))
def split_cmds_from_files(args): def split_cmds_from_files(args):
@ -358,10 +361,10 @@ def split_cmds_from_files(args):
def print_versions(): def print_versions():
import pkg_resources import pkg_resources
print('nvr {}'.format(pkg_resources.require('neovim-remote')[0].version)) print('nvr ' + pkg_resources.require("neovim-remote")[0].version)
print('pynvim {}'.format(pkg_resources.require('pynvim')[0].version)) print('pynvim ' + pkg_resources.require('pynvim')[0].version)
print('psutil {}'.format(pkg_resources.require('psutil')[0].version)) print('psutil ' + pkg_resources.require('psutil')[0].version)
print('Python {}'.format(sys.version.split('\n')[0])) print('Python ' + sys.version.split('\n')[0])
def print_addresses(): def print_addresses():
@ -379,7 +382,7 @@ def print_addresses():
if conn.laddr: if conn.laddr:
addresses.insert(0, conn.laddr) addresses.insert(0, conn.laddr)
except psutil.AccessDenied: except psutil.AccessDenied:
errors.insert(0, 'Access denied for nvim ({})'.format(proc.pid)) errors.insert(0, f'Access denied for nvim ({proc.pid})')
for addr in sorted(addresses): for addr in sorted(addresses):
print(addr) print(addr)
@ -408,7 +411,7 @@ def main(argv=sys.argv, env=os.environ):
print_addresses() print_addresses()
return return
address = options.servername or env.get('NVIM_LISTEN_ADDRESS') or '/tmp/nvimsocket' address = options.servername or env.get('NVIM') or env.get('NVIM_LISTEN_ADDRESS') or '/tmp/nvimsocket'
nvr = Nvr(address, options.s) nvr = Nvr(address, options.s)
nvr.attach() nvr.attach()
@ -468,11 +471,11 @@ def main2(nvr, options, arguments):
try: try:
result = nvr.server.eval(options.remote_expr) result = nvr.server.eval(options.remote_expr)
except: except:
print(textwrap.dedent(""" print(textwrap.dedent(f"""
No valid expression: {} No valid expression: {options.remote_expr}
Test it in Neovim: :echo eval('...') Test it in Neovim: :echo eval('...')
If you want to execute a command, use -c or -cc instead. If you want to execute a command, use -c or -cc instead.
""").format(options.remote_expr)) """))
if type(result) is bytes: if type(result) is bytes:
print(result.decode()) print(result.decode())
elif type(result) is list: elif type(result) is list:
@ -509,14 +512,14 @@ def main2(nvr, options, arguments):
if options.t: if options.t:
try: try:
nvr.server.command("tag {}".format(options.t)) nvr.server.command('tag ' + options.t)
except nvr.server.error as e: except nvr.server.error as e:
print(e) print(e)
sys.exit(1) sys.exit(1)
if options.q: if options.q:
path = nvr.server.funcs.fnameescape(os.environ['PWD']) path = nvr.server.funcs.fnameescape(os.environ['PWD'])
nvr.server.command('lcd {}'.format(path)) nvr.server.command('lcd ' + path)
nvr.server.funcs.setqflist([]) nvr.server.funcs.setqflist([])
if options.q == '-': if options.q == '-':
for line in sys.stdin: for line in sys.stdin:

@ -14,13 +14,13 @@ setup(
description = 'Control nvim processes using "nvr" commandline tool', description = 'Control nvim processes using "nvr" commandline tool',
long_description = long_description, long_description = long_description,
long_description_content_type = 'text/markdown', long_description_content_type = 'text/markdown',
python_requires = '>=3.5', python_requires = '>=3.7',
install_requires = ['pynvim', 'psutil', 'setuptools'], install_requires = ['pynvim', 'psutil', 'setuptools'],
entry_points = { entry_points = {
'console_scripts': ['nvr = nvr.nvr:main'] 'console_scripts': ['nvr = nvr.nvr:main']
}, },
packages = ['nvr'], packages = ['nvr'],
version = '2.4.0', version = '2.4.2',
license = 'MIT', license = 'MIT',
keywords = 'neovim nvim nvr remote helper', keywords = 'neovim nvim nvr remote helper',
classifiers = [ classifiers = [
@ -30,10 +30,6 @@ setup(
'Intended Audience :: End Users/Desktop', 'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers', 'Intended Audience :: Developers',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
], ],
) )

Loading…
Cancel
Save