Debian Codegraph @

vim/autoload/jedi.vim

raw
1 scriptencoding utf-8
2
3 " ------------------------------------------------------------------------
4 " Settings initialization
5 " ------------------------------------------------------------------------
6 let s:deprecations = {
7 \ 'get_definition_command': 'goto_definitions_command',
8 \ 'pydoc': 'documentation_command',
9 \ 'related_names_command': 'usages_command',
10 \ 'autocompletion_command': 'completions_command',
11 \ 'show_function_definition': 'show_call_signatures',
12 \ }
13
14 let s:default_settings = {
15 \ 'use_tabs_not_buffers': 0,
16 \ 'use_splits_not_buffers': 1,
17 \ 'auto_initialization': 1,
18 \ 'auto_vim_configuration': 1,
19 \ 'goto_command': "'<leader>d'",
20 \ 'goto_assignments_command': "'<leader>g'",
21 \ 'goto_definitions_command': "''",
22 \ 'goto_stubs_command': "'<leader>s'",
23 \ 'completions_command': "'<C-Space>'",
24 \ 'call_signatures_command': "'<leader>n'",
25 \ 'usages_command': "'<leader>n'",
26 \ 'rename_command': "'<leader>r'",
27 \ 'rename_command_keep_name': "'<leader>R'",
28 \ 'completions_enabled': 1,
29 \ 'popup_on_dot': 'g:jedi#completions_enabled',
30 \ 'documentation_command': "'K'",
31 \ 'show_call_signatures': has('conceal') ? 1 : 2,
32 \ 'show_call_signatures_delay': 500,
33 \ 'call_signature_escape': "'?!?'",
34 \ 'auto_close_doc': 1,
35 \ 'max_doc_height': 30,
36 \ 'popup_select_first': 1,
37 \ 'quickfix_window_height': 10,
38 \ 'force_py_version': "'auto'",
39 \ 'environment_path': "'auto'",
40 \ 'added_sys_path': '[]',
41 \ 'project_path': "'auto'",
42 \ 'smart_auto_mappings': 0,
43 \ 'case_insensitive_completion': 1,
44 \ 'use_tag_stack': 1
45 \ }
46
47 for [s:key, s:val] in items(s:deprecations)
48 if exists('g:jedi#'.s:key)
49 echom "'g:jedi#".s:key."' is deprecated. Please use 'g:jedi#".s:val."' instead. Sorry for the inconvenience."
50 exe 'let g:jedi#'.s:val.' = g:jedi#'.s:key
51 endif
52 endfor
53
54 for [s:key, s:val] in items(s:default_settings)
55 if !exists('g:jedi#'.s:key)
56 exe 'let g:jedi#'.s:key.' = '.s:val
57 endif
58 endfor
59
60 let s:supports_buffer_usages = has('nvim') || exists('*prop_add')
61
62
63 " ------------------------------------------------------------------------
64 " Python initialization
65 " ------------------------------------------------------------------------
66 let s:script_path = expand('<sfile>:p:h:h')
67
68 function! s:init_python() abort
69 " Use g:jedi#force_py_version for loading Jedi, or fall back to using
70 " `has()` - preferring Python 3.
71 if !has('python3')
72 throw 'jedi-vim requires Vim with support for Python 3.'
73 endif
74 call jedi#setup_python_imports()
75 return 1
76 endfunction
77
78
79 function! jedi#reinit_python() abort
80 let s:_init_python = -1
81 call jedi#init_python()
82 endfunction
83
84
85 " This is meant to be called with `:unsilent` (for &shortmess+=F).
86 function! s:display_exception() abort
87 let error_lines = split(v:exception, '\n')
88 let msg = 'Error: jedi-vim failed to initialize Python: '
89 \ .error_lines[0].' (in '.v:throwpoint.')'
90 if len(error_lines) > 1
91 echohl ErrorMsg
92 echom 'jedi-vim error: '.error_lines[0]
93 for line in error_lines[1:]
94 echom line
95 endfor
96 echohl None
97 let help_cmd = ':JediDebugInfo'
98 if exists(':checkhealth') == 2
99 let help_cmd .= ' / :checkhealth'
100 endif
101 let msg .= printf('. See :messages and/or %s for more information.',
102 \ help_cmd)
103 endif
104 redraw " Redraw to only have the main message by default.
105 echoerr msg
106 endfunction
107
108
109 let s:_init_python = -1
110 function! jedi#init_python() abort
111 if s:_init_python == -1
112 let s:_init_python = 0
113 try
114 let s:_init_python = s:init_python()
115 let s:_init_python = 1
116 catch /^jedi/
117 " Only catch errors from jedi-vim itself here, so that for
118 " unexpected Python exceptions the traceback will be shown
119 " (e.g. with NameError in jedi#setup_python_imports's code).
120 if !exists('g:jedi#squelch_py_warning')
121 unsilent call s:display_exception()
122 endif
123 endtry
124 endif
125 return s:_init_python
126 endfunction
127
128
129 function! jedi#setup_python_imports() abort
130 let g:_jedi_init_error = 0
131 let init_lines = [
132 \ 'import vim',
133 \ 'def _jedi_handle_exc(exc_info):',
134 \ ' try:',
135 \ ' from jedi_vim_debug import format_exc_info',
136 \ ' vim.vars["_jedi_init_error"] = format_exc_info(exc_info)',
137 \ ' except Exception:',
138 \ ' import traceback',
139 \ ' vim.vars["_jedi_init_error"] = "\\n".join(traceback.format_exception(*exc_info))',
140 \ 'try:',
141 \ ' import jedi_vim',
142 \ ' if hasattr(jedi_vim, "jedi_import_error"):',
143 \ ' _jedi_handle_exc(jedi_vim.jedi_import_error)',
144 \ 'except Exception as exc:',
145 \ ' _jedi_handle_exc(sys.exc_info())',
146 \ ]
147 exe 'python3 exec('''.escape(join(init_lines, '\n'), "'").''')'
148 if g:_jedi_init_error isnot 0
149 throw printf('jedi#setup_python_imports: %s', g:_jedi_init_error)
150 endif
151 return 1
152 endfunction
153
154
155 function! jedi#debug_info() abort
156 if &verbose
157 if &filetype !=# 'python'
158 echohl WarningMsg | echo 'You should run this in a buffer with filetype "python".' | echohl None
159 endif
160 endif
161 let spath = shellescape(s:script_path)
162 echo '#### Jedi-vim debug information'
163 echo "\n"
164 echo '##### jedi-vim version'
165 echo "\n"
166 echo ' - jedi-vim git version: '
167 echon substitute(system('git -C '.spath.' describe --tags --always --dirty'), '\v\n$', '', '')
168 echo ' - jedi git submodule status: '
169 echon substitute(system('git -C '.spath.' submodule status pythonx/jedi'), '\v\n$', '', '')
170 echo ' - parso git submodule status: '
171 echon substitute(system('git -C '.spath.' submodule status pythonx/parso'), '\v\n$', '', '')
172 echo "\n"
173 echo '##### Global Python'
174 echo "\n"
175 echo 'Using Python version 3 to access Jedi.'
176 let s:pythonjedi_called = 0
177 try
178 python3 import vim; vim.command('let s:pythonjedi_called = 1')
179 catch
180 echo 'Error when trying to import vim: '.v:exception
181 endtry
182 if !s:pythonjedi_called
183 echohl WarningMsg
184 echom 'python3 failed to run, likely a Python config issue.'
185 if exists(':checkhealth') == 2
186 echom 'Try :checkhealth for more information.'
187 endif
188 echohl None
189 else
190 try
191 python3 from jedi_vim_debug import display_debug_info
192 python3 display_debug_info()
193 catch
194 echohl WarningMsg
195 echo 'Error when running display_debug_info: '.v:exception
196 echohl None
197 endtry
198 endif
199 echo "\n"
200 echo '##### Settings'
201 echo "\n"
202 echo '```'
203 let jedi_settings = items(filter(copy(g:), "v:key =~# '\\v^jedi#'"))
204 let has_nondefault_settings = 0
205 for [k, V] in jedi_settings
206 exe 'let default = '.get(s:default_settings,
207 \ substitute(k, '\v^jedi#', '', ''), "'-'")
208 " vint: -ProhibitUsingUndeclaredVariable
209 if default !=# V
210 echo printf('g:%s = %s (default: %s)', k, string(V), string(default))
211 unlet! V " Fix variable type mismatch with Vim 7.3.
212 let has_nondefault_settings = 1
213 endif
214 " vint: +ProhibitUsingUndeclaredVariable
215 endfor
216 if has_nondefault_settings
217 echo "\n"
218 endif
219 verb set omnifunc? completeopt?
220 echo '```'
221
222 if &verbose
223 echo "\n"
224 echo '#### :version'
225 echo '```'
226 version
227 echo '```'
228 echo "\n"
229 echo '#### :messages'
230 echo '```'
231 messages
232 echo '```'
233 echo "\n"
234 echo '<details><summary>:scriptnames</summary>'
235 echo "\n"
236 echo '```'
237 scriptnames
238 echo '```'
239 echo '</details>'
240 endif
241 endfunction
242
243 " Helper function instead of `python vim.eval()`, and `.command()` because
244 " these also return error definitions.
245 function! jedi#_vim_exceptions(str, is_eval) abort
246 let l:result = {}
247 try
248 if a:is_eval
249 let l:result.result = eval(a:str)
250 else
251 execute a:str
252 let l:result.result = ''
253 endif
254 catch
255 let l:result.exception = v:exception
256 let l:result.throwpoint = v:throwpoint
257 endtry
258 return l:result
259 endfunction
260
261 call jedi#init_python() " Might throw an error.
262
263 " ------------------------------------------------------------------------
264 " functions that call python code
265 " ------------------------------------------------------------------------
266 function! jedi#goto() abort
267 python3 jedi_vim.goto(mode="goto")
268 endfunction
269
270 function! jedi#goto_assignments() abort
271 python3 jedi_vim.goto(mode="assignment")
272 endfunction
273
274 function! jedi#goto_definitions() abort
275 python3 jedi_vim.goto(mode="definition")
276 endfunction
277
278 function! jedi#goto_stubs() abort
279 python3 jedi_vim.goto(mode="stubs")
280 endfunction
281
282 function! jedi#usages() abort
283 if exists('#jedi_usages#BufWinEnter')
284 call jedi#clear_usages()
285 endif
286 python3 jedi_vim.usages()
287 endfunction
288
289 if !s:supports_buffer_usages
290 " Hide usages in the current window.
291 " Only handles the current window due to matchdelete() restrictions.
292 function! jedi#_hide_usages_in_win() abort
293 let winnr = winnr()
294 let matchids = getwinvar(winnr, '_jedi_usages_vim_matchids', [])
295
296 for matchid in matchids[1:]
297 call matchdelete(matchid)
298 endfor
299 call setwinvar(winnr, '_jedi_usages_vim_matchids', [])
300
301 " Remove the autocommands that might have triggered this function.
302 augroup jedi_usages
303 exe 'autocmd! * <buffer='.winbufnr(winnr).'>'
304 augroup END
305 unlet! b:_jedi_usages_needs_clear
306 endfunction
307
308 " Show usages for current window (Vim without textprops only).
309 function! jedi#_show_usages_in_win() abort
310 python3 jedi_vim.highlight_usages_for_vim_win()
311
312 if !exists('#jedi_usages#TextChanged#<buffer>')
313 augroup jedi_usages
314 " Unset highlights on any changes to this buffer.
315 " NOTE: Neovim's API handles movement of highlights, but would only
316 " need to clear highlights that are changed inline.
317 autocmd TextChanged <buffer> call jedi#_clear_buffer_usages()
318
319 " Hide usages when the buffer is removed from the window, or when
320 " entering insert mode (but keep them for later).
321 autocmd BufWinLeave,InsertEnter <buffer> call jedi#_hide_usages_in_win()
322 augroup END
323 endif
324 endfunction
325
326 " Remove usages for the current buffer (and all its windows).
327 function! jedi#_clear_buffer_usages() abort
328 let bufnr = bufnr('%')
329 let nvim_src_ids = getbufvar(bufnr, '_jedi_usages_src_ids', [])
330 if !empty(nvim_src_ids)
331 for src_id in nvim_src_ids
332 " TODO: could only clear highlights below/after changed line?!
333 call nvim_buf_clear_highlight(bufnr, src_id, 0, -1)
334 endfor
335 else
336 call jedi#_hide_usages_in_win()
337 endif
338 endfunction
339 endif
340
341 " Remove/unset global usages.
342 function! jedi#clear_usages() abort
343 augroup jedi_usages
344 autocmd! BufWinEnter
345 autocmd! WinEnter
346 augroup END
347
348 if !s:supports_buffer_usages
349 " Vim without textprops: clear current window,
350 " autocommands will clean others on demand.
351 call jedi#_hide_usages_in_win()
352
353 " Setup autocommands to clear remaining highlights on WinEnter.
354 augroup jedi_usages
355 for b in range(1, bufnr('$'))
356 if getbufvar(b, '_jedi_usages_needs_clear')
357 exe 'autocmd WinEnter <buffer='.b.'> call jedi#_hide_usages_in_win()'
358 endif
359 endfor
360 augroup END
361 endif
362
363 python3 jedi_vim.clear_usages()
364 endfunction
365
366 function! jedi#rename(...) abort
367 python3 jedi_vim.rename()
368 endfunction
369
370 function! jedi#rename_visual(...) abort
371 python3 jedi_vim.rename_visual()
372 endfunction
373
374 function! jedi#rename_keep_name(...) abort
375 python3 jedi_vim.rename(delete_word=False)
376 endfunction
377
378 function! jedi#rename_visual_keep_name(...) abort
379 python3 jedi_vim.rename_visual(use_selected_text_as_prompt_answer=True)
380 endfunction
381
382 function! jedi#completions(findstart, base) abort
383 python3 jedi_vim.completions()
384 endfunction
385
386 function! jedi#enable_speed_debugging() abort
387 python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
388 endfunction
389
390 function! jedi#enable_debugging() abort
391 python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
392 endfunction
393
394 function! jedi#disable_debugging() abort
395 python3 jedi_vim.jedi.set_debug_function(None)
396 endfunction
397
398 function! jedi#py_import(args) abort
399 python3 jedi_vim.py_import()
400 endfun
401
402 function! jedi#choose_environment(args) abort
403 python3 jedi_vim.choose_environment()
404 endfun
405
406 function! jedi#load_project(args) abort
407 python3 jedi_vim.load_project()
408 endfun
409
410 function! jedi#py_import_completions(argl, cmdl, pos) abort
411 python3 jedi_vim.py_import_completions()
412 endfun
413
414 function! jedi#clear_cache(bang) abort
415 if a:bang
416 python3 jedi_vim.jedi.cache.clear_time_caches(True)
417 else
418 python3 jedi_vim.jedi.cache.clear_time_caches(False)
419 endif
420 endfunction
421
422
423 " ------------------------------------------------------------------------
424 " show_documentation
425 " ------------------------------------------------------------------------
426 function! jedi#show_documentation() abort
427 python3 if jedi_vim.show_documentation() is None: vim.command('return')
428
429 let bn = bufnr('__doc__')
430 if bn > 0
431 let wi=index(tabpagebuflist(tabpagenr()), bn)
432 if wi >= 0
433 " If the __doc__ buffer is open in the current tab, jump to it
434 silent execute (wi+1).'wincmd w'
435 else
436 silent execute 'sbuffer '.bn
437 endif
438 else
439 split __doc__
440 endif
441
442 setlocal modifiable
443 setlocal noswapfile
444 setlocal buftype=nofile
445 silent normal! ggdG
446 silent $put=l:doc
447 silent normal! 1Gdd
448 setlocal nomodifiable
449 setlocal nomodified
450 setlocal filetype=rst
451 setlocal foldlevel=200 " do not fold in __doc__
452
453 if l:doc_lines > g:jedi#max_doc_height " max lines for plugin
454 let l:doc_lines = g:jedi#max_doc_height
455 endif
456 execute 'resize '.l:doc_lines
457
458 " quit comands
459 nnoremap <buffer> q ZQ
460 if len(g:jedi#documentation_command)
461 execute 'nnoremap <buffer> '.g:jedi#documentation_command.' ZQ'
462 endif
463 endfunction
464
465 " ------------------------------------------------------------------------
466 " helper functions
467 " ------------------------------------------------------------------------
468
469 function! jedi#add_goto_window(for_usages, len) abort
470 let height = min([a:len, g:jedi#quickfix_window_height])
471
472 " Use :copen to go to the window always - the user should select an entry.
473 execute 'belowright copen '.height
474
475 if &filetype !=# 'qf'
476 echoerr printf('jedi-vim: unexpected ft with current window (%s), please report!', &filetype)
477 endif
478 if g:jedi#use_tabs_not_buffers == 1
479 noremap <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
480 endif
481
482 augroup jedi_goto_window
483 if a:for_usages
484 autocmd BufWinLeave <buffer> call jedi#clear_usages()
485 else
486 autocmd WinLeave <buffer> q " automatically leave, if an option is chosen
487 endif
488 augroup END
489
490 if a:for_usages && !has('nvim')
491 if s:supports_buffer_usages
492 " Setup autocommand for pending highlights with Vim's textprops.
493 " (cannot be added to unlisted buffers)
494 augroup jedi_usages
495 autocmd! BufWinEnter * call s:usages_for_pending_buffers()
496 augroup END
497 else
498 " Setup global autocommand to display any usages for a window.
499 " Gets removed when closing the quickfix window that displays them, or
500 " when clearing them (e.g. on TextChanged).
501 augroup jedi_usages
502 autocmd! BufWinEnter,WinEnter * call jedi#_show_usages_in_win()
503 augroup END
504 endif
505 endif
506 endfunction
507
508 " Highlight usages for a buffer if not done so yet (Neovim only).
509 function! s:usages_for_pending_buffers() abort
510 python3 jedi_vim._handle_pending_usages_for_buf()
511 endfunction
512
513
514 function! jedi#goto_window_on_enter() abort
515 let l:list = getqflist()
516 let l:data = l:list[line('.') - 1]
517 if l:data.bufnr
518 " close goto_window buffer
519 normal! ZQ
520 python3 jedi_vim.set_buffer(vim.eval('bufname(l:data.bufnr)'))
521 call cursor(l:data.lnum, l:data.col)
522 else
523 echohl WarningMsg | echo 'Builtin module cannot be opened.' | echohl None
524 endif
525 endfunction
526
527
528 function! s:syn_stack() abort
529 if !exists('*synstack')
530 return []
531 endif
532 return map(synstack(line('.'), col('.') - 1), "synIDattr(v:val, 'name')")
533 endfunc
534
535
536 function! jedi#do_popup_on_dot_in_highlight() abort
537 let highlight_groups = s:syn_stack()
538 for a in highlight_groups
539 if a ==# 'pythonDoctest'
540 return 1
541 endif
542 endfor
543
544 for a in highlight_groups
545 for b in ['pythonString', 'pythonComment', 'pythonNumber']
546 if a == b
547 return 0
548 endif
549 endfor
550 endfor
551 return 1
552 endfunc
553
554
555 let s:show_call_signatures_last = [0, 0, '']
556 function! jedi#show_call_signatures() abort
557 if s:_init_python == 0
558 return 1
559 endif
560 let [line, col] = [line('.'), col('.')]
561 let curline = getline(line)
562 let reload_signatures = 1
563
564 " Caching. On the same line only.
565 if line == s:show_call_signatures_last[0]
566 " Check if the number of special signs before or after the
567 " cursor has not changed since the last call, which means that the
568 " argument position was not changed and we can skip repainting.
569 let prevcol = s:show_call_signatures_last[1]
570 let prevline = s:show_call_signatures_last[2]
571 let no_special = '[^,()=]'
572 if substitute(curline[:col-2], no_special, '', 'g')
573 \ == substitute(prevline[:prevcol-2], no_special, '', 'g')
574 \ && substitute(curline[(col-2):], no_special, '', 'g')
575 \ == substitute(prevline[(prevcol-2):], no_special, '', 'g')
576 let reload_signatures = 0
577 endif
578 endif
579 let s:show_call_signatures_last = [line, col, curline]
580
581 if reload_signatures
582 python3 jedi_vim.show_call_signatures()
583 endif
584 endfunction
585
586
587 function! jedi#clear_call_signatures() abort
588 if s:_init_python == 0
589 return 1
590 endif
591
592 let s:show_call_signatures_last = [0, 0, '']
593 python3 jedi_vim.clear_call_signatures()
594 endfunction
595
596
597 function! jedi#configure_call_signatures() abort
598 augroup jedi_call_signatures
599 autocmd! * <buffer>
600 if g:jedi#show_call_signatures == 2 " Command line call signatures
601 autocmd InsertEnter <buffer> let g:jedi#first_col = s:save_first_col()
602 endif
603 autocmd InsertEnter <buffer> let s:show_call_signatures_last = [0, 0, '']
604 autocmd InsertLeave <buffer> call jedi#clear_call_signatures()
605 if g:jedi#show_call_signatures_delay > 0
606 autocmd InsertEnter <buffer> let b:_jedi_orig_updatetime = &updatetime
607 \ | let &updatetime = g:jedi#show_call_signatures_delay
608 autocmd InsertLeave <buffer> if exists('b:_jedi_orig_updatetime')
609 \ | let &updatetime = b:_jedi_orig_updatetime
610 \ | unlet b:_jedi_orig_updatetime
611 \ | endif
612 autocmd CursorHoldI <buffer> call jedi#show_call_signatures()
613 else
614 autocmd CursorMovedI <buffer> call jedi#show_call_signatures()
615 endif
616 augroup END
617 endfunction
618
619
620 " Determine where the current window is on the screen for displaying call
621 " signatures in the correct column.
622 function! s:save_first_col() abort
623 if bufname('%') ==# '[Command Line]' || winnr('$') == 1
624 return 0
625 endif
626
627 let startwin = winnr()
628 let winwidth = winwidth(0)
629 if winwidth == &columns
630 return 0
631 elseif winnr('$') == 2
632 return startwin == 1 ? 0 : (winwidth(1) + 1)
633 elseif winnr('$') == 3
634 if startwin == 1
635 return 0
636 endif
637 let ww1 = winwidth(1)
638 let ww2 = winwidth(2)
639 let ww3 = winwidth(3)
640 if ww1 + ww2 + ww3 + 2 == &columns
641 if startwin == 2
642 return ww1 + 1
643 else
644 return ww1 + ww2 + 2
645 endif
646 elseif startwin == 2
647 if ww2 + ww3 + 1 == &columns
648 return 0
649 else
650 return ww1 + 1
651 endif
652 else " startwin == 3
653 if ww2 + ww3 + 1 == &columns
654 return ww2 + 1
655 else
656 return ww1 + 1
657 endif
658 endif
659 endif
660 return 0
661 endfunction
662
663
664 function! jedi#complete_string(autocomplete) abort
665 if a:autocomplete
666 if !(g:jedi#popup_on_dot && jedi#do_popup_on_dot_in_highlight())
667 return ''
668 endif
669
670 let s:saved_completeopt = &completeopt
671 set completeopt-=longest
672 set completeopt+=menuone
673 set completeopt-=menu
674 if &completeopt !~# 'noinsert\|noselect'
675 " Patch 775 introduced noinsert and noselect, previously these
676 " options didn't exist. Setting them in earlier versions results in
677 " errors (E474).
678 if has('patch-7.4-775')
679 if g:jedi#popup_select_first
680 set completeopt+=noinsert
681 else
682 set completeopt+=noselect
683 endif
684 else
685 " To pass the tests we use this, it seems to get the closest to
686 " the other options. I'm really not sure if this properly
687 " works, but VIM 7.4-775 is already pretty old, so it might not
688 " be a problem anymore in a few years.
689 set completeopt+=longest
690 endif
691 endif
692 elseif pumvisible()
693 return "\<C-n>"
694 endif
695 return "\<C-x>\<C-o>\<C-r>=jedi#complete_opened(".a:autocomplete.")\<CR>"
696 endfunction
697
698
699 function! jedi#complete_opened(autocomplete) abort
700 if a:autocomplete
701 let &completeopt = s:saved_completeopt
702 unlet s:saved_completeopt
703 elseif pumvisible() && g:jedi#popup_select_first && stridx(&completeopt, 'longest') > -1
704 return "\<Down>"
705 endif
706 return ''
707 endfunction
708
709
710 function! jedi#smart_auto_mappings() abort
711 " Auto put import statement after from module.name<space> and complete
712 if search('\m^\s*from\s\+[A-Za-z0-9._]\{1,50}\%#\s*$', 'bcn', line('.'))
713 " Enter character and start completion.
714 return "\<space>import \<C-r>=jedi#complete_string(1)\<CR>"
715 endif
716 return "\<space>"
717 endfunction
718
719
720 function! jedi#setup_completion() abort
721 " We need our own omnifunc, so this overrides the omnifunc set by
722 " $VIMRUNTIME/ftplugin/python.vim.
723 setlocal omnifunc=jedi#completions
724
725 " map ctrl+space for autocompletion
726 if g:jedi#completions_command ==# '<C-Space>'
727 " In terminals, <C-Space> sometimes equals <Nul>.
728 imap <buffer> <Nul> <C-Space>
729 smap <buffer> <Nul> <C-Space>
730 endif
731 if len(g:jedi#completions_command)
732 execute 'inoremap <expr> <buffer> '.g:jedi#completions_command.' jedi#complete_string(0)'
733 " A separate mapping for select mode: deletes and completes.
734 execute 'snoremap <expr> <buffer> '.g:jedi#completions_command." '\<C-g>c'.jedi#complete_string(0)"
735 endif
736 endfunction
737
738 "python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False)
739 "python3 jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout)
740
741 " vim: set et ts=4: