Simplify vim options changes

This commit is contained in:
Ben Jackson 2018-06-03 14:29:51 +01:00
commit 553ad95404
2 changed files with 35 additions and 19 deletions

View file

@ -266,28 +266,30 @@ class DebugSession( object ):
self._codeView = code.CodeView( vim.current.window )
# Call stack
vim.command( 'topleft 50vspl' )
vim.command( 'enew' )
self._stackTraceView = stack_trace.StackTraceView( self,
self._connection,
vim.current.buffer )
with utils.TemporaryVimOptions( { 'splitright': False,
'equalalways': False, } ):
vim.command( 'topleft 50vspl' )
vim.command( 'enew' )
self._stackTraceView = stack_trace.StackTraceView( self,
self._connection,
vim.current.buffer )
with utils.TemporaryVimOption( 'splitbelow', False ):
with utils.TemporaryVimOption( 'eadirection', 'ver' ):
with utils.TemporaryVimOption( 'equalalways', 1 ):
# Watches
vim.command( 'spl' )
vim.command( 'enew' )
watch_win = vim.current.window
with utils.TemporaryVimOptions( { 'splitbelow': False,
'eadirection': 'ver',
'equalalways': True } ):
# Watches
vim.command( 'spl' )
vim.command( 'enew' )
watch_win = vim.current.window
# Variables
vim.command( 'spl' )
vim.command( 'enew' )
vars_win = vim.current.window
# Variables
vim.command( 'spl' )
vim.command( 'enew' )
vars_win = vim.current.window
self._variablesView = variables.VariablesView( self._connection,
vars_win,
watch_win )
self._variablesView = variables.VariablesView( self._connection,
vars_win,
watch_win )
with utils.TemporaryVimOption( 'splitbelow', True ):

View file

@ -96,6 +96,20 @@ def RestoreCurrentBuffer( window ):
vim.current.buffer = old_buffer
@contextlib.contextmanager
def TemporaryVimOptions( opts ):
old_value = {}
try:
for option, value in opts.items():
old_value[ option ] = vim.options[ option ]
vim.options[ option ] = value
yield
finally:
for option, value in old_value.items():
vim.options[ option ] = value
@contextlib.contextmanager
def TemporaryVimOption( opt, value ):
old_value = vim.options[ opt ]