فهرست منبع

Added check for Vim 'hidden' option when trying to open result in the same buffer

Davit Samvelyan 11 سال پیش
والد
کامیت
b9109af709
2فایلهای تغییر یافته به همراه16 افزوده شده و 4 حذف شده
  1. 5 2
      README.md
  2. 11 2
      python/ycm/vimsupport.py

+ 5 - 2
README.md

@@ -1339,8 +1339,11 @@ Default: `1`
 ### The `g:ycm_goto_buffer_command` option
 
 Defines where `GoTo*` commands result should be opened.
-Can take one of the following values: `[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab' ]`
-If this option is set to `'same-buffer'` but current buffer is modified then result will be opened in horizontal split.
+Can take one of the following values:
+`[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab' ]`
+If this option is set to the `'same-buffer'` but current buffer can not
+be switched (when buffer is modified and `nohidden` option is set),
+then result will be opened in horizontal split.
 
 Default: `'same-buffer'`
     let g:ycm_goto_buffer_command = 'same-buffer'

+ 11 - 2
python/ycm/vimsupport.py

@@ -72,7 +72,8 @@ def GetBufferOption( buffer_object, option ):
 
 
 def BufferModified( buffer_object ):
-  return bool( int( GetBufferOption( buffer_object, 'mod' ) ) )
+  return buffer_object.options[ 'mod' ]
+
 
 def GetUnsavedAndCurrentBufferData():
   buffers_data = {}
@@ -238,6 +239,14 @@ def VimExpressionToPythonType( vim_expression ):
     return result
 
 
+def HiddenEnabled( buffer_object ):
+  return vim.options[ 'hid' ]
+
+
+def BufferIsUsable( buffer_object ):
+  return not BufferModified( buffer_object ) or HiddenEnabled( buffer_object )
+
+
 # Both |line| and |column| need to be 1-based
 def JumpToLocation( filename, line, column ):
   # Add an entry to the jumplist
@@ -252,7 +261,7 @@ def JumpToLocation( filename, line, column ):
     # jumplist.
     user_command = user_options_store.Value( 'goto_buffer_command' )
     command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
-    if command == 'edit' and BufferModified( vim.current.buffer ):
+    if command == 'edit' and not BufferIsUsable( vim.current.buffer ):
       command = 'split'
     vim.command( 'keepjumps {0} {1}'.format( command, filename ) )
   vim.current.window.cursor = ( line, column - 1 )