Skip to content

Commit 6f8a59b

Browse files
committed
Added :GhostTextStop when autostart = 0
1 parent bcebc1f commit 6f8a59b

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

autoload/nvim_ghost.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ function! s:start_server_or_request_focus()
2323
endif
2424
endfunction
2525

26+
function! nvim_ghost#disable()
27+
call nvim_ghost#helper#session_closed()
28+
autocmd! nvim_ghost
29+
if !exists('g:_nvim_ghost_supports_focus')
30+
autocmd! _nvim_ghost_does_not_support_focus
31+
endif
32+
endfunction
33+
2634
function! nvim_ghost#enable(defer = 0)
2735
if !a:defer
2836
call s:start_server_or_request_focus()

binary.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from simple_websocket_server import WebSocket
1919
from simple_websocket_server import WebSocketServer
2020

21-
BUILD_VERSION: str = "v0.4.1"
21+
BUILD_VERSION: str = "v0.5.0"
2222

2323
WINDOWS: bool = os.name == "nt"
2424
LOCALHOST: str = "127.0.0.1" if WINDOWS else "localhost"
@@ -45,6 +45,8 @@
4545
sys.exit("Port must be a number")
4646
GHOST_PORT: int = int(SERVER_PORT)
4747

48+
AUTOEXIT: bool = bool(os.environ.get("NVIM_GHOST_AUTO_EXIT"))
49+
NVIM_ADDRESSES = [FOCUSED_NVIM_ADDRESS] if FOCUSED_NVIM_ADDRESS is not None else []
4850

4951
# chdir to folder containing binary
5052
# otherwise the logs are generated whereever the server was started from (i.e curdir)
@@ -242,6 +244,10 @@ def _focus_responder(self, query_string):
242244
FOCUSED_NVIM_ADDRESS = address
243245
log(f"Focus {address}")
244246

247+
global NVIM_ADDRESSES
248+
if FOCUSED_NVIM_ADDRESS not in NVIM_ADDRESSES:
249+
NVIM_ADDRESSES.append(FOCUSED_NVIM_ADDRESS)
250+
245251
def _session_closed_responder(self, query_string):
246252
"""
247253
A neovim instance is reporting that it has been closed
@@ -256,6 +262,11 @@ def _session_closed_responder(self, query_string):
256262
if address == FOCUSED_NVIM_ADDRESS:
257263
FOCUSED_NVIM_ADDRESS = None
258264

265+
global NVIM_ADDRESSES
266+
NVIM_ADDRESSES.remove(address)
267+
if AUTOEXIT and len(NVIM_ADDRESSES) == 0:
268+
self.server.running = False
269+
259270
def _respond(self, text):
260271
"""
261272
Send text response with Content-Type text/plain

binary_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.4.1
1+
v0.5.0

plugin/nvim_ghost.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ let g:nvim_ghost_binary_path = g:nvim_ghost_installation_dir .. 'nvim-ghost-bina
2626

2727
" Setup environment
2828
let $NVIM_LISTEN_ADDRESS = v:servername
29+
let $NVIM_GHOST_AUTO_EXIT = !g:nvim_ghost_autostart
2930
let $NVIM_GHOST_SUPER_QUIET = g:nvim_ghost_super_quiet
3031
let $NVIM_GHOST_LOGGING_ENABLED = g:nvim_ghost_logging_enabled
3132
let $GHOSTTEXT_SERVER_PORT = g:nvim_ghost_server_port
@@ -51,10 +52,11 @@ endif
5152
" If autostart is disabled, add GhostTextStart command
5253
if !g:nvim_ghost_autostart
5354
command! GhostTextStart
54-
\ let g:nvim_ghost_disabled = 0
5555
\| call nvim_ghost#init()
5656
\| doau <nomodeline> nvim_ghost UIEnter
57-
\| delcommand GhostTextEnable
57+
\| delcommand GhostTextStart
58+
\| command GhostTextStop
59+
\| call nvim_ghost#disable()
5860
finish
5961
endif
6062

0 commit comments

Comments
 (0)