Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to start a new process instead of overriding the current one #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions nvr/nvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import argparse
import multiprocessing
import subprocess
import os
import re
import sys
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.')
Expand Down Expand Up @@ -588,4 +599,3 @@ def err_cb(error):

if __name__ == '__main__':
main()