From 74951adcc756b5de111397086cdf1832d4522101 Mon Sep 17 00:00:00 2001 From: Nader Akoury Date: Fri, 11 Nov 2016 07:53:01 -0800 Subject: [PATCH 1/4] Address #1366 by reusing a single preview buffer * Additionally set the preview buffer to be unlisted so it does not interfere with commands like :bnext --- python/ycm/vimsupport.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 876a0e3a..5ca2c46c 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -895,6 +895,15 @@ def OpenFileInPreviewWindow( filename ): vim.command( 'silent! pedit! ' + filename ) +def GetPreviewBuffer(): + """ Get the preview buffer. Create it if it does not exist. """ + variable_name = 'g:ycm_preview_buffer_name' + if not VariableExists( variable_name ): + SetVariableValue( variable_name, vim.eval( 'tempname()' ) ) + + return GetVariableValue( variable_name ) + + def WriteToPreviewWindow( message ): """ Display the supplied message in the preview window """ @@ -907,7 +916,7 @@ def WriteToPreviewWindow( message ): ClosePreviewWindow() - OpenFileInPreviewWindow( vim.eval( 'tempname()' ) ) + OpenFileInPreviewWindow( GetPreviewBuffer() ) if JumpToPreviewWindow(): # We actually got to the preview window. By default the preview window can't @@ -922,6 +931,7 @@ def WriteToPreviewWindow( message ): vim.current.buffer.options[ 'swapfile' ] = False vim.current.buffer.options[ 'modifiable' ] = False vim.current.buffer.options[ 'readonly' ] = True + vim.current.buffer.options[ 'buflisted' ] = False # We need to prevent closing the window causing a warning about unsaved # file, so we pretend to Vim that the buffer has not been changed. From 9c93244d3b59a92e2378dc80a54b4fe007a6af63 Mon Sep 17 00:00:00 2001 From: Nader Akoury Date: Fri, 11 Nov 2016 10:15:22 -0800 Subject: [PATCH 2/4] Addressed review comments and fixed tests --- python/ycm/tests/vimsupport_test.py | 2 ++ python/ycm/vimsupport.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index 131a4360..ab95d0e5 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -1262,6 +1262,8 @@ def WriteToPreviewWindow_test( vim_current, vim_command ): call( 'modifiable', True ), call( 'readonly', False ), call( 'buftype', 'nofile' ), + call( 'bufhidden', 'wipe' ), + call( 'buflisted', False ), call( 'swapfile', False ), call( 'modifiable', False ), call( 'modified', False ), diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 5ca2c46c..f30de92a 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -928,6 +928,8 @@ def WriteToPreviewWindow( message ): vim.current.buffer[:] = message.splitlines() vim.current.buffer.options[ 'buftype' ] = 'nofile' + vim.current.buffer.options[ 'bufhidden' ] = 'wipe' + vim.current.buffer.options[ 'buflisted' ] = False vim.current.buffer.options[ 'swapfile' ] = False vim.current.buffer.options[ 'modifiable' ] = False vim.current.buffer.options[ 'readonly' ] = True From 659746eaaf4ddc976df93364188592f0405949aa Mon Sep 17 00:00:00 2001 From: Nader Akoury Date: Fri, 11 Nov 2016 10:53:26 -0800 Subject: [PATCH 3/4] Doh, forgot to revert my previous changes. Fixed! --- python/ycm/vimsupport.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index f30de92a..be41b607 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -895,15 +895,6 @@ def OpenFileInPreviewWindow( filename ): vim.command( 'silent! pedit! ' + filename ) -def GetPreviewBuffer(): - """ Get the preview buffer. Create it if it does not exist. """ - variable_name = 'g:ycm_preview_buffer_name' - if not VariableExists( variable_name ): - SetVariableValue( variable_name, vim.eval( 'tempname()' ) ) - - return GetVariableValue( variable_name ) - - def WriteToPreviewWindow( message ): """ Display the supplied message in the preview window """ @@ -916,7 +907,7 @@ def WriteToPreviewWindow( message ): ClosePreviewWindow() - OpenFileInPreviewWindow( GetPreviewBuffer() ) + OpenFileInPreviewWindow( vim.eval( 'tempname()' ) ) if JumpToPreviewWindow(): # We actually got to the preview window. By default the preview window can't From f4f12f3c9b3c839d9bee60bbcf53d23c2aa74f64 Mon Sep 17 00:00:00 2001 From: Nader Akoury Date: Fri, 11 Nov 2016 11:28:20 -0800 Subject: [PATCH 4/4] Fix another test failure * Because I cannot seem to run the tests locally I am relying on the CI tests which kind of sucks... --- python/ycm/vimsupport.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index be41b607..73351053 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -924,7 +924,6 @@ def WriteToPreviewWindow( message ): vim.current.buffer.options[ 'swapfile' ] = False vim.current.buffer.options[ 'modifiable' ] = False vim.current.buffer.options[ 'readonly' ] = True - vim.current.buffer.options[ 'buflisted' ] = False # We need to prevent closing the window causing a warning about unsaved # file, so we pretend to Vim that the buffer has not been changed.