Skip to content

Commit

Permalink
Added :GhostTextStop when autostart = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
subnut committed Mar 18, 2023
1 parent bcebc1f commit 6f8a59b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions autoload/nvim_ghost.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 12 additions & 1 deletion binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion binary_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.1
v0.5.0
6 changes: 4 additions & 2 deletions plugin/nvim_ghost.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <nomodeline> nvim_ghost UIEnter
\| delcommand GhostTextEnable
\| delcommand GhostTextStart
\| command GhostTextStop
\| call nvim_ghost#disable()
finish
endif

Expand Down

0 comments on commit 6f8a59b

Please sign in to comment.