From 37d851bb34552edfc3b1abd4d1034d4fdf46408f Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 3 Dec 2015 12:11:28 +0100 Subject: [PATCH] Implement --remote --- nvim-remote.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 nvim-remote.py diff --git a/nvim-remote.py b/nvim-remote.py new file mode 100755 index 0000000..73ef749 --- /dev/null +++ b/nvim-remote.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +""" +Copyright (c) 2015 Marco Hinz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +""" + +import sys +import os +import subprocess +import argparse + +from neovim import attach + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--remote', action='append', help='Edit in a Vim server if possible') + parser.add_argument('--remote-silent', help="Same, don't complain if there is no server") + parser.add_argument('--remote-wait', help='As --remote but wait for files to have been edited') + parser.add_argument('--remote-wait-silent', help="Same, don't complain if there is no server") + parser.add_argument('--remote-tab', help='As --remote but use tab page per file') + parser.add_argument('--remote-send', help='Send to a Vim server and exit') + parser.add_argument('--remote-expr', help='Evaluate in a Vim server and print result ') + args, unused = parser.parse_known_args() + + sockpath = os.environ.get('NVIM_LISTEN_ADDRESS') + if sockpath is None: + sockpath = '/tmp/nvimsocket' + + try: + nvim = attach('socket', path='/tmp/nvimsocket') + except FileNotFoundError: + print("""Problem: Can't find unix socket: /tmp/nvimsocket + Solution: Start a new server: NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim""") + sys.exit(1) + + if args.remote: + for fname in args.remote: + nvim.command('edit {}'.format(fname)) + + if unused: + os.putenv('VIMRUNTIME', '/data/repo/neovim/runtime') + subprocess.Popen(['/data/repo/neovim/build/bin/nvim'] + unused) + +if __name__ == '__main__': + main()