MCPcopy Index your code
hub / github.com/ycm-core/YouCompleteMe / OpenFilename

Function OpenFilename

python/ycm/vimsupport.py:1295–1360  ·  view source on GitHub ↗

Open a file in Vim. Following options are available: - command: specify which Vim command is used to open the file. Choices are same-buffer, horizontal-split, vertical-split, and new-tab (default: horizontal-split); - size: set the height of the window for a horizontal split or the width for

( filename, options = {} )

Source from the content-addressed store, hash-verified

1293
1294
1295def OpenFilename( filename, options = {} ):
1296 """Open a file in Vim. Following options are available:
1297 - command: specify which Vim command is used to open the file. Choices
1298 are same-buffer, horizontal-split, vertical-split, and new-tab (default:
1299 horizontal-split);
1300 - size: set the height of the window for a horizontal split or the width for
1301 a vertical one (default: '');
1302 - fix: set the winfixheight option for a horizontal split or winfixwidth for
1303 a vertical one (default: False). See :h winfix for details;
1304 - focus: focus the opened file (default: False);
1305 - watch: automatically watch for changes (default: False). This is useful
1306 for logs;
1307 - position: set the position where the file is opened (default: start).
1308 Choices are 'start' and 'end'.
1309 - mods: The vim <mods> for the command, such as :vertical"""
1310
1311 # Set the options.
1312 command = GetVimCommand( options.get( 'command', 'horizontal-split' ),
1313 'horizontal-split' )
1314 size = ( options.get( 'size', '' ) if command in [ 'split', 'vsplit' ] else
1315 '' )
1316 focus = options.get( 'focus', False )
1317
1318 # There is no command in Vim to return to the previous tab so we need to
1319 # remember the current tab if needed.
1320 if not focus and command == 'tabedit':
1321 previous_tab = GetIntValue( 'tabpagenr()' )
1322 else:
1323 previous_tab = None
1324
1325 # Open the file.
1326 try:
1327 vim.command( f'{ options.get( "mods", "" ) }'
1328 f'{ size }'
1329 f'{ command } '
1330 f'{ filename }' )
1331 # When the file we are trying to jump to has a swap file,
1332 # Vim opens swap-exists-choices dialog and throws vim.error with E325 error,
1333 # or KeyboardInterrupt after user selects one of the options which actually
1334 # opens the file (Open read-only/Edit anyway).
1335 except vim.error as e:
1336 if 'E325' not in str( e ):
1337 raise
1338
1339 # Otherwise, the user might have chosen Quit. This is detectable by the
1340 # current file not being the target file
1341 if filename != GetCurrentBufferFilepath():
1342 return
1343 except KeyboardInterrupt:
1344 # Raised when the user selects "Abort" after swap-exists-choices
1345 return
1346
1347 _SetUpLoadedBuffer( command,
1348 filename,
1349 options.get( 'fix', False ),
1350 options.get( 'position', 'start' ),
1351 options.get( 'watch', False ) )
1352

Callers 1

_OpenFileInSplitIfNeededFunction · 0.85

Calls 7

GetVimCommandFunction · 0.85
GetIntValueFunction · 0.85
GetCurrentBufferFilepathFunction · 0.85
_SetUpLoadedBufferFunction · 0.85
JumpToTabFunction · 0.85
JumpToPreviousWindowFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected