diff --git a/autoload/nvim_ghost.vim b/autoload/nvim_ghost.vim index 6952642..c78a7d2 100644 --- a/autoload/nvim_ghost.vim +++ b/autoload/nvim_ghost.vim @@ -23,6 +23,14 @@ function! s:start_server_or_request_focus() endif endfunction +function! nvim_ghost#disable() + call nvim_ghost#helper#session_closed() + autocmd! nvim_ghost + if !exists('g:_nvim_ghost_supports_focus') + autocmd! _nvim_ghost_does_not_support_focus + endif +endfunction + function! nvim_ghost#enable(defer = 0) if !a:defer call s:start_server_or_request_focus() diff --git a/binary.py b/binary.py index 5cf4e29..b24821b 100644 --- a/binary.py +++ b/binary.py @@ -18,7 +18,7 @@ from simple_websocket_server import WebSocket from simple_websocket_server import WebSocketServer -BUILD_VERSION: str = "v0.4.1" +BUILD_VERSION: str = "v0.5.0" WINDOWS: bool = os.name == "nt" LOCALHOST: str = "127.0.0.1" if WINDOWS else "localhost" @@ -45,6 +45,8 @@ sys.exit("Port must be a number") GHOST_PORT: int = int(SERVER_PORT) +AUTOEXIT: bool = bool(os.environ.get("NVIM_GHOST_AUTO_EXIT")) +NVIM_ADDRESSES = [FOCUSED_NVIM_ADDRESS] if FOCUSED_NVIM_ADDRESS is not None else [] # chdir to folder containing binary # otherwise the logs are generated whereever the server was started from (i.e curdir) @@ -242,6 +244,10 @@ def _focus_responder(self, query_string): FOCUSED_NVIM_ADDRESS = address log(f"Focus {address}") + global NVIM_ADDRESSES + if FOCUSED_NVIM_ADDRESS not in NVIM_ADDRESSES: + NVIM_ADDRESSES.append(FOCUSED_NVIM_ADDRESS) + def _session_closed_responder(self, query_string): """ A neovim instance is reporting that it has been closed @@ -256,6 +262,11 @@ def _session_closed_responder(self, query_string): if address == FOCUSED_NVIM_ADDRESS: FOCUSED_NVIM_ADDRESS = None + global NVIM_ADDRESSES + NVIM_ADDRESSES.remove(address) + if AUTOEXIT and len(NVIM_ADDRESSES) == 0: + self.server.running = False + def _respond(self, text): """ Send text response with Content-Type text/plain diff --git a/binary_version b/binary_version index 5aff472..b043aa6 100644 --- a/binary_version +++ b/binary_version @@ -1 +1 @@ -v0.4.1 +v0.5.0 diff --git a/plugin/nvim_ghost.vim b/plugin/nvim_ghost.vim index 1c39f90..9c1ce75 100644 --- a/plugin/nvim_ghost.vim +++ b/plugin/nvim_ghost.vim @@ -26,6 +26,7 @@ let g:nvim_ghost_binary_path = g:nvim_ghost_installation_dir .. 'nvim-ghost-bina " Setup environment let $NVIM_LISTEN_ADDRESS = v:servername +let $NVIM_GHOST_AUTO_EXIT = !g:nvim_ghost_autostart let $NVIM_GHOST_SUPER_QUIET = g:nvim_ghost_super_quiet let $NVIM_GHOST_LOGGING_ENABLED = g:nvim_ghost_logging_enabled let $GHOSTTEXT_SERVER_PORT = g:nvim_ghost_server_port @@ -51,10 +52,11 @@ endif " If autostart is disabled, add GhostTextStart command if !g:nvim_ghost_autostart command! GhostTextStart - \ let g:nvim_ghost_disabled = 0 \| call nvim_ghost#init() \| doau nvim_ghost UIEnter - \| delcommand GhostTextEnable + \| delcommand GhostTextStart + \| command GhostTextStop + \| call nvim_ghost#disable() finish endif