Opens a new buffer if we have to or does nothing. Returns True in case of success.
(path: Optional[Path], options='', using_tagstack=False)
| 1137 | |
| 1138 | @catch_and_print_exceptions |
| 1139 | def set_buffer(path: Optional[Path], options='', using_tagstack=False): |
| 1140 | """ |
| 1141 | Opens a new buffer if we have to or does nothing. Returns True in case of |
| 1142 | success. |
| 1143 | """ |
| 1144 | path = str(path or '') |
| 1145 | # Check both, because it might be an empty string |
| 1146 | if path in (vim.current.buffer.name, os.path.abspath(vim.current.buffer.name)): |
| 1147 | return True |
| 1148 | |
| 1149 | path = relpath(path) |
| 1150 | # options are what you can to edit the edit options |
| 1151 | if int(vim_eval('g:jedi#use_tabs_not_buffers')) == 1: |
| 1152 | _tabnew(path, options) |
| 1153 | elif not vim_eval('g:jedi#use_splits_not_buffers') in [1, '1']: |
| 1154 | user_split_option = vim_eval('g:jedi#use_splits_not_buffers') |
| 1155 | split_options = { |
| 1156 | 'top': 'topleft split', |
| 1157 | 'left': 'topleft vsplit', |
| 1158 | 'right': 'botright vsplit', |
| 1159 | 'bottom': 'botright split', |
| 1160 | 'winwidth': 'vs' |
| 1161 | } |
| 1162 | if (user_split_option == 'winwidth' and |
| 1163 | vim.current.window.width <= 2 * int(vim_eval( |
| 1164 | "&textwidth ? &textwidth : 80"))): |
| 1165 | split_options['winwidth'] = 'sp' |
| 1166 | if user_split_option not in split_options: |
| 1167 | print('Unsupported value for g:jedi#use_splits_not_buffers: {0}. ' |
| 1168 | 'Valid options are: {1}.'.format( |
| 1169 | user_split_option, ', '.join(split_options.keys()))) |
| 1170 | else: |
| 1171 | vim_command(split_options[user_split_option] + " %s" % escape_file_path(path)) |
| 1172 | else: |
| 1173 | if int(vim_eval("!&hidden && &modified")) == 1: |
| 1174 | if not vim_eval("bufname('%')"): |
| 1175 | echo_highlight('Cannot open a new buffer, use `:set hidden` or save your buffer') |
| 1176 | return False |
| 1177 | else: |
| 1178 | vim_command('w') |
| 1179 | if using_tagstack: |
| 1180 | return True |
| 1181 | vim_command('edit %s %s' % (options, escape_file_path(path))) |
| 1182 | # sometimes syntax is being disabled and the filetype not set. |
| 1183 | if int(vim_eval('!exists("g:syntax_on")')) == 1: |
| 1184 | vim_command('syntax enable') |
| 1185 | if int(vim_eval("&filetype != 'python'")) == 1: |
| 1186 | vim_command('set filetype=python') |
| 1187 | return True |
| 1188 | |
| 1189 | |
| 1190 | @catch_and_print_exceptions |
no test coverage detected