From cb39e2b511b1662a667c3275c439e968c6527f3e Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sat, 11 Jul 2020 11:44:15 +0100 Subject: [PATCH] Allow closing of the UI windows; check valid flags and set buffers to be hidden. delete them on Reset --- python3/vimspector/output.py | 32 +++++++++++++++++-------------- python3/vimspector/stack_trace.py | 2 +- python3/vimspector/utils.py | 24 ++++++++++++----------- python3/vimspector/variables.py | 4 ++-- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index 59d1857..4599e04 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -77,9 +77,10 @@ class OutputView( object ): self._ToggleFlag( category, True ) # Scroll the buffer - with utils.RestoreCurrentWindow(): - with utils.RestoreCurrentBuffer( self._window ): - self._ShowOutput( category ) + if self._window.valid: + with utils.RestoreCurrentWindow(): + with utils.RestoreCurrentBuffer( self._window ): + self._ShowOutput( category ) def ConnectionUp( self, connection ): self._connection = connection @@ -96,18 +97,17 @@ class OutputView( object ): if tab_buffer.is_job: utils.CleanUpCommand( tab_buffer.job_category or category, self._api_prefix ) - try: - vim.command( 'bdelete! {0}'.format( tab_buffer.buf.number ) ) - except vim.error as e: - # FIXME: For now just ignore the "no buffers were deleted" error - if 'E516' not in str( e ): - raise + utils.CleanUpHiddenBuffer( tab_buffer.buf ) + # FIXME: nunmenu the WinBar ? self._buffers = {} def _ShowOutput( self, category ): + if not self._window.valid: + return + utils.JumpToWindow( self._window ) - vim.command( 'bu {0}'.format( self._buffers[ category ].buf.name ) ) + vim.current.buffer = self._buffers[ category ].buf vim.command( 'normal G' ) def ShowOutput( self, category ): @@ -146,8 +146,10 @@ class OutputView( object ): def _ToggleFlag( self, category, flag ): if self._buffers[ category ].flag != flag: self._buffers[ category ].flag = flag - with utils.LetCurrentWindow( self._window ): - self._RenderWinBar( category ) + + if self._window.valid: + with utils.LetCurrentWindow( self._window ): + self._RenderWinBar( category ) def RunJobWithOutput( self, category, cmd ): @@ -155,6 +157,9 @@ class OutputView( object ): def _CreateBuffer( self, category, file_name = None, cmd = None ): + if not self._window.valid: + return + with utils.LetCurrentWindow( self._window ): with utils.RestoreCurrentBuffer( self._window ): @@ -185,8 +190,7 @@ class OutputView( object ): utils.SetUpPromptBuffer( tab_buffer.buf, 'vimspector.Console', '> ', - 'vimspector#EvaluateConsole', - hidden=True ) + 'vimspector#EvaluateConsole' ) else: utils.SetUpHiddenBuffer( tab_buffer.buf, diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index b146424..088ac7c 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -81,7 +81,7 @@ class StackTraceView( object ): def Reset( self ): self.Clear() - # TODO: delete the buffer ? + utils.CleanUpHiddenBuffer( self._buf ) def LoadThreads( self, infer_current_frame ): pending_request = False diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index a868c7f..8d7d3d4 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -86,15 +86,17 @@ def CleanUpCommand( name, api_prefix ): name ) ) +def CleanUpHiddenBuffer( buf ): + try: + vim.command( 'bdelete! {}'.format( buf.number ) ) + except vim.error as e: + # FIXME: For now just ignore the "no buffers were deleted" error + if 'E516' not in str( e ): + raise + + def SetUpScratchBuffer( buf, name ): - buf.options[ 'buftype' ] = 'nofile' - buf.options[ 'swapfile' ] = False - buf.options[ 'modifiable' ] = False - buf.options[ 'modified' ] = False - buf.options[ 'readonly' ] = True - buf.options[ 'buflisted' ] = False - buf.options[ 'bufhidden' ] = 'wipe' - buf.name = name + SetUpHiddenBuffer( buf, name ) def SetUpHiddenBuffer( buf, name ): @@ -108,7 +110,7 @@ def SetUpHiddenBuffer( buf, name ): buf.name = name -def SetUpPromptBuffer( buf, name, prompt, callback, hidden=False ): +def SetUpPromptBuffer( buf, name, prompt, callback ): # This feature is _super_ new, so only enable when available if not Exists( '*prompt_setprompt' ): return SetUpHiddenBuffer( buf, name ) @@ -119,7 +121,8 @@ def SetUpPromptBuffer( buf, name, prompt, callback, hidden=False ): buf.options[ 'modified' ] = False buf.options[ 'readonly' ] = False buf.options[ 'buflisted' ] = False - buf.options[ 'bufhidden' ] = 'wipe' if not hidden else 'hide' + buf.options[ 'bufhidden' ] = 'hide' + buf.options[ 'textwidth' ] = 0 buf.name = name vim.eval( "prompt_setprompt( {0}, '{1}' )".format( buf.number, @@ -177,7 +180,6 @@ def RestoreCurrentWindow(): @contextlib.contextmanager def RestoreCurrentBuffer( window ): - # TODO: Don't trigger autoccommands when shifting buffers old_buffer = window.buffer try: yield diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 6826b59..528c570 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -200,8 +200,8 @@ class VariablesView( object ): for k, v in self._oldoptions.items(): vim.options[ k ] = v - vim.command( 'bdelete! ' + str( self._watch.buf.number ) ) - vim.command( 'bdelete! ' + str( self._vars.buf.number ) ) + utils.CleanUpHiddenBuffer( self._vars.buf ) + utils.CleanUpHiddenBuffer( self._watch.buf ) def LoadScopes( self, frame ): def scopes_consumer( message ):