From 459340cf2cc95185d24592b01aa414259f6445dd Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Wed, 15 Jun 2022 11:35:00 -0700 Subject: [PATCH] Add an option to start a new process instead of overriding the current one --- nvr/nvr.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/nvr/nvr.py b/nvr/nvr.py index 705b1d6..8aa77bb 100644 --- a/nvr/nvr.py +++ b/nvr/nvr.py @@ -24,6 +24,7 @@ import argparse import multiprocessing +import subprocess import os import re import sys @@ -77,13 +78,20 @@ def execute_new_nvim_process(self, silent, nvr, options, arguments): args = args.split(' ') if args else ['nvim'] args.extend(['--listen', self.address]) + if options.start_separate_process: + # If we're starting a separate process then + # let it start before we try to attach to it + subprocess.Popen(args, env=os.environ) + multiprocessing.Process(target=self.try_attach, args=(args[0], nvr, options, arguments)).start() - try: - os.execvpe(args[0], args, os.environ) - except FileNotFoundError: - print(f'[!] Can\'t start new nvim process: `{args[0]}` is not in $PATH.') - sys.exit(1) + if not options.start_separate_process: + try: + os.execvpe(args[0], args, os.environ) + except FileNotFoundError: + print(f'[!] Can\'t start new nvim process: `{args[0]}` is not in $PATH.') + sys.exit(1) + sys.exit(0) def read_stdin_into_buffer(self, cmd): self.server.command(cmd) @@ -300,6 +308,9 @@ def parse_args(argv): parser.add_argument('--nostart', action = 'store_true', help = 'If no process is found, do not start a new one.') + parser.add_argument('--start-separate-process', + action = 'store_true', + help = 'Start a separate process instead of replacing the current one.') parser.add_argument('--version', action = 'store_true', help = 'Show the nvr version.') @@ -588,4 +599,3 @@ def err_cb(error): if __name__ == '__main__': main() -