Skip to content

Commit eb3d800

Browse files
committed
Add helper for quitting Nvim from the client
Also fix the error type raised when the connection is closed to IOError
1 parent e28f127 commit eb3d800

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

neovim/api/nvim.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ def err_write(self, msg):
175175
"""Print `msg` as an error message."""
176176
return self._session.request('vim_err_write', msg)
177177

178+
def quit(self, quit_command='qa!'):
179+
"""Send a quit command to Nvim.
180+
181+
By default, the quit command is 'qa!' which will make Nvim quit without
182+
saving anything.
183+
"""
184+
try:
185+
self.command(quit_command)
186+
except IOError:
187+
# sending a quit command will raise an IOError because the
188+
# connection is closed before a response is received. Safe to
189+
# ignore it.
190+
pass
191+
178192

179193
class Current(object):
180194

neovim/msgpack_rpc/event_loop/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _on_signal(self, signum):
159159

160160
def _on_error(self, error):
161161
debug(error)
162-
self._error = Exception(error)
162+
self._error = IOError(error)
163163
self.stop()
164164

165165
def _on_interrupt(self):

0 commit comments

Comments
 (0)