2
0
mirror of https://github.com/mhinz/neovim-remote synced 2024-11-11 13:10:34 +00:00

Handle files beginning with - for --remote options

Small tradeoff: You get no error anymore when you provide no arguments to
--remote and friends.

Internally this results in an empty list instead of None. This is important,
because otherwise you'd get an error with `--remote -- foo`, because `--` and
`foo` would be parsed into the remaining arguments and --remote had no argument.

In return it's now possible to provide files beginning with a dash to any
--remote option. Leading -- before those files is not needed.

Equivalent:

    --remote --file
    --remote -- --file

Fixes https://github.com/mhinz/neovim-remote/issues/43
This commit is contained in:
Marco Hinz 2017-06-19 14:55:27 +02:00
parent 53ce66cf98
commit 7422ee6d90
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F

View File

@ -199,7 +199,7 @@ def parse_args(argv):
description = desc) description = desc)
parser.add_argument('--remote', parser.add_argument('--remote',
nargs = '+', nargs = '*',
metavar = '<file>', metavar = '<file>',
help = 'Use :edit to open files in a remote instance. If no remote instance is found, throw an error and run nvim locally instead.') help = 'Use :edit to open files in a remote instance. If no remote instance is found, throw an error and run nvim locally instead.')
parser.add_argument('--remote-wait', parser.add_argument('--remote-wait',
@ -207,7 +207,7 @@ def parse_args(argv):
metavar = '<file>', metavar = '<file>',
help = 'Like --remote, but block until all buffers opened by this option get deleted or remote instance exits.') help = 'Like --remote, but block until all buffers opened by this option get deleted or remote instance exits.')
parser.add_argument('--remote-silent', parser.add_argument('--remote-silent',
nargs = '+', nargs = '*',
metavar = '<file>', metavar = '<file>',
help = 'Like --remote, but throw no error if remote instance is not found.') help = 'Like --remote, but throw no error if remote instance is not found.')
parser.add_argument('--remote-wait-silent', parser.add_argument('--remote-wait-silent',
@ -216,19 +216,19 @@ def parse_args(argv):
help = 'Combines --remote-wait and --remote-silent.') help = 'Combines --remote-wait and --remote-silent.')
parser.add_argument('--remote-tab', '-p', parser.add_argument('--remote-tab', '-p',
nargs = '+', nargs = '*',
metavar = '<file>', metavar = '<file>',
help = 'Like --remote, but use :tabedit.') help = 'Like --remote, but use :tabedit.')
parser.add_argument('--remote-tab-wait', parser.add_argument('--remote-tab-wait',
nargs = '+', nargs = '*',
metavar = '<file>', metavar = '<file>',
help = 'Like --remote-wait, but use :tabedit.') help = 'Like --remote-wait, but use :tabedit.')
parser.add_argument('--remote-tab-silent', parser.add_argument('--remote-tab-silent',
nargs = '+', nargs = '*',
metavar = '<file>', metavar = '<file>',
help = 'Like --remote-silent, but use :tabedit.') help = 'Like --remote-silent, but use :tabedit.')
parser.add_argument('--remote-tab-wait-silent', parser.add_argument('--remote-tab-wait-silent',
nargs = '+', nargs = '*',
metavar = '<file>', metavar = '<file>',
help = 'Like --remote-wait-silent, but use :tabedit.') help = 'Like --remote-wait-silent, but use :tabedit.')
@ -272,7 +272,6 @@ def parse_args(argv):
metavar = '<errorfile>', metavar = '<errorfile>',
help = 'Read errorfile into quickfix list and display first error.') help = 'Read errorfile into quickfix list and display first error.')
if len(argv) == 1: if len(argv) == 1:
parser.print_help() parser.print_help()
sys.exit(0) sys.exit(0)
@ -325,25 +324,24 @@ def main(argv=sys.argv, env=os.environ):
except ValueError: except ValueError:
pass pass
# Arguments not consumed by flags, are fed to --remote. if flags.remote is not None:
if arguments: neovim.execute(flags.remote + arguments, 'edit')
elif flags.remote_wait is not None:
neovim.execute(flags.remote_wait + arguments, 'edit', wait=True)
elif flags.remote_silent is not None:
neovim.execute(flags.remote_silent + arguments, 'edit', silent=True)
elif flags.remote_wait_silent is not None:
neovim.execute(flags.remote_wait_silent + arguments, 'edit', silent=True, wait=True)
elif flags.remote_tab is not None:
neovim.execute(flags.remote_tab + arguments, 'tabedit')
elif flags.remote_tab_wait is not None:
neovim.execute(flags.remote_tab_wait + arguments, 'tabedit', wait=True)
elif flags.remote_tab_silent is not None:
neovim.execute(flags.remote_tab_silent + arguments, 'tabedit', silent=True)
elif flags.remote_tab_wait_silent is not None:
neovim.execute(flags.remote_tab_wait_silent + arguments, 'tabedit', silent=True, wait=True)
elif arguments:
neovim.execute(arguments, 'edit') neovim.execute(arguments, 'edit')
elif flags.remote:
neovim.execute(flags.remote, 'edit')
elif flags.remote_wait:
neovim.execute(flags.remote_wait, 'edit', wait=True)
elif flags.remote_silent:
neovim.execute(flags.remote_silent, 'edit', silent=True)
elif flags.remote_wait_silent:
neovim.execute(flags.remote_wait_silent, 'edit', silent=True, wait=True)
elif flags.remote_tab:
neovim.execute(flags.remote_tab, 'tabedit')
elif flags.remote_tab_wait:
neovim.execute(flags.remote_tab_wait, 'tabedit', wait=True)
elif flags.remote_tab_silent:
neovim.execute(flags.remote_tab_silent, 'tabedit', silent=True)
elif flags.remote_tab_wait_silent:
neovim.execute(flags.remote_tab_wait_silent, 'tabedit', silent=True, wait=True)
if flags.remote_send and neovim.is_attached(): if flags.remote_send and neovim.is_attached():
neovim.server.input(flags.remote_send) neovim.server.input(flags.remote_send)