pax_global_header00006660000000000000000000000064122043750440014513gustar00rootroot0000000000000052 comment=e01eadb9edb05b6a9dd8c53defa5b89511a9ec32 .gitignore000066400000000000000000000001471220437504400130510ustar00rootroot00000000000000*~ *.sw? *.py[cod] .coverage .tox .mr.developer.cfg .project .pydevproject .ropeproject .idea doc/tags .gitmodules000066400000000000000000000001171220437504400132330ustar00rootroot00000000000000[submodule "jedi"] path = jedi url = https://github.com/davidhalter/jedi.git AUTHORS.txt000066400000000000000000000006031220437504400127440ustar00rootroot00000000000000Main Authors ============ David Halter (@davidhalter) Contributors (in order of contributions) ======================================== tek (@tek) mattn (@mattn) Danilo Bargen (@dbrgn) Artur Dryomov (@ming13) Akinori Hattori (@hattya) Luper Rouch (@flupke) Emily Strickland (@lilix) Mathieu Comandon (@strycore) Jean-Louis Fuchs (@ganwell) Nick Hurley (@todesschaf) Tinche (@Tinche) CONTRIBUTING.md000066400000000000000000000006251220437504400133130ustar00rootroot00000000000000Pull Requests are great (on the **dev** branch)! 1. Fork the Repo on github. 2. Add yourself to AUTHORS.txt 3. Push to your fork and submit a **pull request to the dev branch**. My **master** branch is a 100% stable (should be). I only push to it after I am certain that things are working out. Many people are using Jedi directly from the github master branch. Please use Pep8 to style your code. LICENSE.txt000066400000000000000000000172311220437504400127060ustar00rootroot00000000000000Licensed under the GNU LGPL v3 or later. Copyright (C) 2012 David Halter . =============================================================================== GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. README.rst000066400000000000000000000071721220437504400125550ustar00rootroot00000000000000################################################# jedi-vim - awesome Python autocompletion with VIM ################################################# *If you have any comments or feature requests, please tell me! I really want to know, what you think about Jedi and jedi-vim.* jedi-vim is a is a VIM binding to the awesome autocompletion library *Jedi*. Here are some pictures: .. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_complete.png Completion for almost anything (Ctrl+Space). .. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_function.png Display of function/class bodies, docstrings. .. image:: https://github.com/davidhalter/jedi/raw/master/docs/_screenshots/screenshot_pydoc.png Pydoc support (with highlighting, Shift+k). There is also support for goto and renaming. Get the latest from `github `_. You can get the Jedi library documentation `here `_. Support ======= The Jedi library supports most of Python's core features. From decorators to generators, there is broad support. Installation ============ You might want to use `pathogen `_ to install jedi in VIM. Also you need a VIM version that was compiled with ``+python``, which is typical for most distributions on Linux. The first thing you need after that is an up-to-date version of Jedi. You can either get it via ``pip install jedi`` or with ``git submodule update --init`` in your jedi-vim repository. The autocompletion can be used with , if you want it to work with you can use `supertab `_. On Arch Linux, you can also install jedi-vim from AUR: `vim-jedi `__. Options ======= Jedi is by default automatically initialized. If you don't want that I suggest you disable the auto-initialization in your ``.vimrc``: .. code-block:: vim let g:jedi#auto_initialization = 0 There are also some VIM options (like ``completeopt``) which are automatically initialized, if you don't want that: .. code-block:: vim let g:jedi#auto_vim_configuration = 0 The goto is by default on . If you want to change that: .. code-block:: vim let g:jedi#goto_command = "g" ``get_definition`` is by default on . If you want to change that: .. code-block:: vim let g:jedi#get_definition_command = "d" Showing the pydoc is by default on ``K`` If you want to change that: .. code-block:: vim let g:jedi#pydoc = "K" If you are a person who likes to use VIM-buffers not tabs, you might want to put that in your ``.vimrc``: .. code-block:: vim let g:jedi#use_tabs_not_buffers = 0 Jedi automatically starts the completion, if you type a dot, e.g. ``str.``, if you don't want this: .. code-block:: vim let g:jedi#popup_on_dot = 0 Jedi selects the first line of the completion menu: for a better typing-flow and usually saves one keypress. .. code-block:: vim let g:jedi#popup_select_first = 0 There's some support for refactoring: .. code-block:: vim let g:jedi#rename_command = "r" And you can list all names that are related (have the same origin): .. code-block:: vim let g:jedi#related_names_command = "n" If you want to change the default autocompletion command: .. code-block:: vim let g:jedi#autocompletion_command = "" By default you get a window that displays the function definition you're currently in. If you don't want that: .. code-block:: vim let g:jedi#show_function_definition = "0" after/000077500000000000000000000000001220437504400121605ustar00rootroot00000000000000after/syntax/000077500000000000000000000000001220437504400135065ustar00rootroot00000000000000after/syntax/python.vim000066400000000000000000000030401220437504400155410ustar00rootroot00000000000000if g:jedi#show_function_definition == 1 && has('conceal') " conceal is normal for vim >= 7.3 let e = g:jedi#function_definition_escape let l1 = e.'jedi=[^'.e.']*'.e.'[^'.e.']*'.e.'jedi'.e let l2 = e.'jedi=\?[^'.e.']*'.e exe 'syn match jediIgnore "'.l2.'" contained conceal' setlocal conceallevel=2 syn match jediFatSymbol "*" contained conceal syn match jediFat "\*[^*]\+\*" contained contains=jediFatSymbol syn match jediSpace "\v[ ]+( )@=" contained exe 'syn match jediFunction "'.l1.'" keepend extend contains=jediIgnore,jediFat,jediSpace' hi def link jediIgnore Ignore hi def link jediFatSymbol Ignore hi def link jediSpace Normal hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555 hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey " override defaults (add jediFunction to contains) syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction syn region pythonString \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" \ contains=pythonEscape,@Spell,jediFunction syn region pythonString \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction syn region pythonRawString \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" \ contains=@Spell,jediFunction syn region pythonRawString \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend \ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction endif autoload/000077500000000000000000000000001220437504400126675ustar00rootroot00000000000000autoload/jedi.vim000066400000000000000000000122051220437504400143170ustar00rootroot00000000000000" ------------------------------------------------------------------------ " functions that call python code " ------------------------------------------------------------------------ function! jedi#goto() Python jedi_vim.goto() endfunction function! jedi#get_definition() Python jedi_vim.goto(is_definition=True) endfunction function! jedi#related_names() Python jedi_vim.goto(is_related_name=True) endfunction function! jedi#rename(...) Python jedi_vim.rename() endfunction function! jedi#complete(findstart, base) Python jedi_vim.complete() endfunction function! jedi#show_func_def() Python jedi_vim.show_func_def() endfunction function! jedi#enable_speed_debugging() Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False) endfunction function! jedi#enable_debugging() Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout) endfunction function! jedi#disable_debugging() Python jedi_vim.jedi.set_debug_function(None) endfunction " ------------------------------------------------------------------------ " show_pydoc " ------------------------------------------------------------------------ function! jedi#show_pydoc() Python jedi_vim.show_pydoc() if bufnr("__doc__") > 0 " If the __doc__ buffer is open in the current window, jump to it silent execute "sbuffer ".bufnr("__doc__") else split '__doc__' endif setlocal modifiable setlocal noswapfile setlocal buftype=nofile silent normal! ggdG silent $put=l:doc silent normal! 1Gdd setlocal nomodifiable setlocal nomodified setlocal filetype=rst if l:doc_lines > 30 " max lines for plugin let l:doc_lines = 30 endif execute "resize ".l:doc_lines " quit comands nnoremap q ZQ nnoremap K ZQ " highlight python code within rst unlet! b:current_syntax syn include @rstPythonScript syntax/python.vim " 4 spaces syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript " >>> python code -> (doctests) syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript let b:current_syntax = "rst" endfunction " ------------------------------------------------------------------------ " helper functions " ------------------------------------------------------------------------ function! jedi#new_buffer(path) if g:jedi#use_tabs_not_buffers Python jedi_vim.tabnew(jedi_vim.escape_file_path(vim.eval('a:path'))) else if !&hidden && &modified w endif Python vim.command('edit ' + jedi_vim.escape_file_path(vim.eval('a:path'))) endif " sometimes syntax is being disabled and the filetype not set. if !exists("g:syntax_on") syntax enable endif if &filetype != 'python' set filetype=python endif endfunction function! jedi#add_goto_window() set lazyredraw cclose execute 'belowright copen '.g:jedi#quickfix_window_height set nolazyredraw if g:jedi#use_tabs_not_buffers == 1 map :call jedi#goto_window_on_enter() endif au WinLeave q " automatically leave, if an option is chosen redraw! endfunction function! jedi#goto_window_on_enter() let l:list = getqflist() let l:data = l:list[line('.') - 1] if l:data.bufnr " close goto_window buffer normal ZQ call jedi#new_buffer(bufname(l:data.bufnr)) call cursor(l:data.lnum, l:data.col) else echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None endif endfunction function! jedi#syn_stack() if !exists("*synstack") return [] endif return map(synstack(line('.'), col('.') - 1), 'synIDattr(v:val, "name")') endfunc function! jedi#do_popup_on_dot() let highlight_groups = jedi#syn_stack() for a in highlight_groups if a == 'pythonDoctest' return 1 endif endfor for a in highlight_groups for b in ['pythonString', 'pythonComment', 'pythonNumber'] if a == b return 0 endif endfor endfor return 1 endfunc function! jedi#configure_function_definition() autocmd InsertLeave Python jedi_vim.clear_func_def() autocmd CursorMovedI call jedi#show_func_def() endfunction if has('python') command! -nargs=1 Python python else command! -nargs=1 Python python3 end Python << PYTHONEOF """ here we initialize the jedi stuff """ import vim # update the system path, to include the jedi path import sys import os sys.path.insert(0, os.path.join(vim.eval('expand(":p:h:h")'), 'jedi')) # to display errors correctly import traceback # update the sys path to include the jedi_vim script sys.path.insert(1, os.path.join(vim.eval('expand(":p:h:h")'), 'plugin')) import jedi_vim sys.path.pop(1) PYTHONEOF "Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout, speed=True, warnings=False, notices=False) "Python jedi_vim.jedi.set_debug_function(jedi_vim.print_to_stdout) " vim: set et ts=4: doc/000077500000000000000000000000001220437504400116245ustar00rootroot00000000000000doc/jedi-vim.txt000066400000000000000000000364011220437504400140750ustar00rootroot00000000000000*jedi-vim.txt* - For Vim version 7.3 - Last change: 2013/3/1 __ _______ _______ __ ____ ____ __ .___ ___.~ | | | ____|| \ | | \ \ / / | | | \/ |~ | | | |__ | .--. || | _____\ \/ / | | | \ / |~ .--. | | | __| | | | || | |______\ / | | | |\/| |~ | `--' | | |____ | '--' || | \ / | | | | | |~ \______/ |_______||_______/ |__| \__/ |__| |__| |__|~ jedi-vim - awesome Python autocompletion with Vim ============================================================================== Contents *jedi-vim-contents* 1. Introduction |jedi-vim-introduction| 2. Installation |jedi-vim-installation| 2.0. Requirements |jedi-vim-installation-requirements| 2.1. Manually |jedi-vim-installation-manually| 2.2. Using Pathogen |jedi-vim-installation-pathogen| 2.3. Using Vundle |jedi-vim-installation-vundle| 3. Supported Python features |jedi-vim-support| 4. Usage |jedi-vim-usage| 5. Mappings |jedi-vim-mappings| 5.1. Start completion |g:jedi#autocompletion_command| 5.2. Go to definition |g:jedi#goto_command| 5.3. Get original definition |g:jedi#get_definition_command| 5.4. Show documentation |g:jedi#pydoc_command| 5.5. Rename variables |g:jedi#rename_command| 5.6. Show related names |g:jedi#related_names_command| 6. Configuration |jedi-vim-configuration| 6.1. auto_initialization |g:jedi#auto_initialization| 6.2. auto_vim_configuration |g:jedi#auto_vim_configuration| 6.3. popup_on_dot |g:jedi#popup_on_dot| 6.4. popup_select_first |g:jedi#popup_select_first| 6.5. auto_close_doc |g:jedi#auto_close_doc| 6.6. show_function_definition |g:jedi#show_function_def| 6.7. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers| 6.8. squelch_py_warning |g:jedi#squelch_py_warning| 7. Contributing |jedi-vim-contributing| 8. License |jedi-vim-license| ============================================================================== 1. Introduction *jedi-vim-introduction* Jedi-vim is a is a Vim binding to the awesome Python autocompletion library `jedi`. Among jedi's (and, therefore, jedi-vim's) features are: - Completion for a wide array of Python features (see |jedi-vim-support|) - Robust in dealing with syntax errors and wrong indentation - Parses complex module/function/class structures - Infers function arguments from Sphinx/Epydoc strings - Doesn't execute Python code - Supports Virtualenv - Supports Python 2.5+ and 3.2+ By leveraging this library, jedi-vim adds the following capabilities to Vim: - Displaying function/class bodies - "Go to definition" command - Displaying docstrings - Renaming and refactoring - Looking up related names ============================================================================== 2. Installation *jedi-vim-installation* ------------------------------------------------------------------------------ 2.0. Requirements *jedi-vim-installation-requirements* First of all, jedi-vim requires Vim to be compiled with the `+python` option. The jedi library has to be installed for jedi-vim to work properly. You can install it first, by using e.g. your distribution's package manager, or by using pip: > pip install jedi However, you can also install it as a git submodule if you don't want to use jedi for anything but this plugin. How to do this is detailed below. ------------------------------------------------------------------------------ 2.1. Installing manually *jedi-vim-installation-manually* 1a. Get the latest repository from Github: > git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim 1b. If you want to install jedi as a submodule instead, issue this command: > git clone --recursive http://github.com/davidhalter/jedi-vim 2. Put the plugin files into their respective folders in your vim runtime directory (usually ~/.vim). Be sure to pay attention to the directory structure! 3. Update the Vim help tags with > :helptags /doc ------------------------------------------------------------------------------ 2.1. Installing using Pathogen *jedi-vim-installation-pathogen* Pathogen simplifies installation considerably. 1.a Clone the git repository into your bundles directory: > git clone http://github.com/davidhalter/jedi-vim path/to/bundles/jedi-vim 1b. Again, if you want to install jedi as a submodule, use this command instead: > git clone --recursive http://github.com/davidhalter/jedi-vim ------------------------------------------------------------------------------ 2.3. Installing using Vundle *jedi-vim-installation-vundle* 1. Vundle automatically downloads subrepositories as git submodules, so you will automatically get the jedi library with the jedi-vim plugin. Add the following to the Bundles section in your .vimrc file: > Bundle 'git://github.com/davidhalter/jedi-vim' 2. Issue the following command in Vim: > :BundleInstall Help tags are generated automatically, so you should be good to go. ============================================================================== 3. Supported Python features *jedi-vim-support* The jedi library does all the hard work behind the scenes. It supports completion of a large number of Python features, among them: - Builtins - Multiple `return`s or `yield`s - Tuple assignments/array indexing/dictionary indexing - `with`-statement/exception handling - `*args` and `**kwargs` - Decorators, lambdas, closures - Generators, iterators - Some descriptors: `property`/`staticmethod`/`classmethod` - Some magic methods: `__call__`, `__iter__`, `__next__`, `__get__`, `__getitem__`, `__init__` - `list.append()`, `set.add()`, `list.extend()`, etc. - (Nested) list comprehensions and ternary expressions - Relative `import`s - `getattr()`/`__getattr__`/`__getattribute__` - Function annotations (py3k feature, are being ignored at the moment, but are parsed) - Class decorators (py3k feature, are being ignored at the moment, but are parsed) - Simple/usual `sys.path` modifications - `isinstance` checks for `if`/`while`/`assert` case, that doesn’t work with Jedi Note: This list is not necessarily up to date. For a complete list of features, please refer to the Jedi documentation at http://jedi.readthedocs.org. ============================================================================== 4. Usage *jedi-vim-usage* With the default settings, autocompletion can be triggered by typing . The first entry will automatically be selected, so you can press to insert it into your code or keep typing and narrow down your completion options. The usual and / keybindings work as well. Autocompletion is also triggered by typing a period in insert mode. Since periods rarely occur in Python code outside of method/import lookups, this is handy to have (but can be disabled). When it encounters a new module, jedi might take a few seconds to parse that module's contents. Afterwards, the contents are cached and completion will be almost instantaneous. ============================================================================== 5. Key Bindings *jedi-vim-keybindings* All keybindings can be mapped by setting the appropriate global option. For example, to set the keybinding for starting omnicompletion to instead of , add the following setting to your .vimrc file: > let g:jedi#autocompletion_command = "" Note: If you have |g:jedi#auto_initialization| set to 0, you have to create a mapping yourself by calling a function: > " Using for omnicompletion inoremap " Use r (by default <\-r>) for renaming nnoremap r :call jedi#rename() " etc. ------------------------------------------------------------------------------ 5.1. `g:jedi#autocompletion_command` *g:jedi#autocompletion_command* Function: n/a; see above Default: Start completion Performs autocompletion (or omnicompletion, to be precise). ------------------------------------------------------------------------------ 5.2. `g:jedi#goto_command` *g:jedi#goto_command* Function: `jedi#goto()` Default: g Go to definition This function finds the first definition of the function/class under the cursor. It produces an error if the definition is not in a Python file. ------------------------------------------------------------------------------ 5.3. `g:jedi#get_definition_command` *g:jedi#get_definition_command* Function: `jedi#get_definition()` Default: d Go to original definition This command tries to find the original definition of the function/class under the cursor. Just like the `jedi#goto()` function, it does not work if the definition isn't in a Python source file. The difference between `jedi#goto()` and `jedi#get_definition()` is that the former doesn't perform recursive lookups. Take, for example, the following module structure: > # file1.py: from file2 import foo # file2.py: from file3 import bar as foo # file3.py def bar(): pass The `jedi#goto()` function will take you to the "from file2 import foo" statement in file1.py, while the `jedi#get_definition()` function will take you all the way to the "def bar():" line in file3.py. ------------------------------------------------------------------------------ 5.4. `g:jedi#pydoc` *g:jedi#pydoc_command* Function: `jedi#show_pydoc()` Default: Show pydoc documentation This shows the pydoc documentation for the item currently under the cursor. The documentation is opened in a horizontally split buffer. ------------------------------------------------------------------------------ 5.5. `g:jedi#rename_command` *g:jedi#rename_command* Function: `jedi#rename()` Default: r Rename variables Jedi-vim deletes the word currently under the cursor and puts Vim in insert mode, where the user is expected to enter the new variable name. Upon leaving insert mode, jedi-vim then renames all occurences of the old variable name with the new one. The number of performed renames is displayed in the command line. ------------------------------------------------------------------------------ 5.6. `g:jedi#related_names_command` *g:jedi#related_names_command* Function: `jedi#related_names()` Default: n Show related names The quickfix window is populated with a list of all names which point to the definition of the name under the cursor. ============================================================================== 6. Configuration *jedi-vim-configuration* Note: You currently have to set these options in your .vimrc. Setting them in an ftplugin (e.g. ~/.vim/ftplugin/python/jedi-vim-settings.vim) will not work because jedi-vim is not set up as an filetype plugin, but as a "regular" plugin. ------------------------------------------------------------------------------ 6.1. `g:jedi#auto_initialization` *g:jedi#auto_initialization* Upon initialization, jedi-vim performs the following steps: 1. Set the current buffers 'omnifunc' to its own completion function `jedi#complete` 2. Create mappings to commands specified in |jedi-vim-mappings| 3. Call `jedi#configure_function_definition()` if `g:jedi#show_function_definition` is set You can disable the default initialization routine by setting this option to 0. Beware that you have to perform the above steps yourself, though. Options: 0 or 1 Default: 1 (Perform automatic initialization) ------------------------------------------------------------------------------ 6.2. `g:jedi#auto_vim_configuration` *g:jedi#auto_vim_configuration* Jedi-vim sets 'completeopt' to `menuone,longest,preview` by default. It also remaps to in insert mode. If you want to keep your own configuration, disable this setting. Options: 0 or 1 Default: 1 (Set 'completeopt' and mapping as described above) ------------------------------------------------------------------------------ 6.3. `g:jedi#popup_on_dot` *g:jedi#popup_on_dot* Jedi-vim automatically starts completion upon typing a period in insert mode. However, when working with large modules, this can slow down your typing flow since you have to wait for jedi to parse the module and show the completion menu. By disabling this setting, completion is only started when you manually press the completion key. Options: 0 or 1 Default: 1 (Start completion on typing a period) ------------------------------------------------------------------------------ 6.4. `g:jedi#popup_select_first` *g:jedi#popup_select_first* Upon starting completion, jedi-vim can automatically select the first entry that pops up (without actually inserting it). This leads to a better typing flow: As you type more characters, the entries in the completion menu are narrowed down. If they are narrowed down enough, you can just press to insert the first match. Options: 0 or 1 Default: 1 (Automatically select first completion entry) ------------------------------------------------------------------------------ 6.5. `g:jedi#auto_close_doc` *g:jedi#auto_close_doc* When doing completion, jedi-vim shows the docstring of the currently selected item in a preview window. By default, this window is being closed after insertion of a completion item. Set this to 1 to leave the preview window open even after leaving insert mode. This could be useful if you want to browse longer docstrings. Options: 0 or 1 Default: 1 (Automatically close preview window upon leaving insert mode) ------------------------------------------------------------------------------ 6.6. `g:jedi#show_function_definition` *g:jedi#show_function_def* Jedi-vim can display a small window detailing the arguments of the currently completed function and highlighting the currently selected argument. This can be disabled by setting this option to 0. Options: 0 or 1 Default: 1 (Show function definition window) Note: This setting is ignored if |g:jedi#auto_initialization| is set to 0. In that case, if you want to see function definitions, you have to set it up manually by calling a function in your configuration file: > call jedi#configure_function_definition() ------------------------------------------------------------------------------ 6.7. `g:jedi#use_tabs_not_buffers` *g:jedi#use_tabs_not_buffers* By default, jedi-vim opens a new tab if you use the "go to", "show definition", or "related names" commands. When you set this option to 0, they open in the current buffer instead. Options: 0 or 1 Default: 1 (Command output is put in a new tab) ------------------------------------------------------------------------------ 6.8. `g:jedi#squelch_py_warning` *g:jedi#squelch_py_warning* When Vim has not been compiled with +python, jedi-vim shows a warning to that effect and aborts loading itself. Set this to 1 to suppress that warning. Options: 0 or 1 Default: 0 (Warning is shown) ============================================================================== 7. Contributing *jedi-vim-contributing* If you have any comments or feature requests, please tell me! I really want to know what you think about jedi and jedi-vim. ============================================================================== 8. License *jedi-vim-license* Jedi-vim is licensed under the GNU LGPL v3 license or later. vim: textwidth=78 tabstop=8 filetype=help:norightleft: ftplugin/000077500000000000000000000000001220437504400127075ustar00rootroot00000000000000ftplugin/python/000077500000000000000000000000001220437504400142305ustar00rootroot00000000000000ftplugin/python/jedi.vim000066400000000000000000000043031220437504400156600ustar00rootroot00000000000000let b:did_ftplugin = 1 if !has('python') && !has('python3') finish endif " ------------------------------------------------------------------------ " Initialization of jedi-vim " ------------------------------------------------------------------------ if g:jedi#auto_initialization setlocal omnifunc=jedi#complete " map ctrl+space for autocompletion if g:jedi#autocompletion_command == "" " in terminals, sometimes equals inoremap pumvisible() \|\| &omnifunc == '' ? \ "\C-n>" : \ "\C-x>\C-o>=pumvisible() ?" . \ "\"\\c-n>\\c-p>\\c-n>\" :" . \ "\" \\bs>\\C-n>\"\" endif execute "inoremap ".g:jedi#autocompletion_command." " " goto / get_definition / related_names execute "noremap ".g:jedi#goto_command." :call jedi#goto()" execute "noremap ".g:jedi#get_definition_command." :call jedi#get_definition()" execute "noremap ".g:jedi#related_names_command." :call jedi#related_names()" " rename execute "noremap ".g:jedi#rename_command." :call jedi#rename()" " pydoc execute "nnoremap ".g:jedi#pydoc." :call jedi#show_pydoc()" if g:jedi#show_function_definition == 1 && has('conceal') call jedi#configure_function_definition() endif end if g:jedi#auto_vim_configuration setlocal completeopt=menuone,longest,preview if len(mapcheck('', 'i')) == 0 inoremap end end if g:jedi#popup_on_dot if stridx(&completeopt, 'longest') > -1 if g:jedi#popup_select_first inoremap . .=jedi#do_popup_on_dot() ? "\C-X>\C-O>\C-N>" : "" else inoremap . .=jedi#do_popup_on_dot() ? "\C-X>\C-O>" : "" end else inoremap . .=jedi#do_popup_on_dot() ? "\C-X>\C-O>\C-P>" : "" end end if g:jedi#auto_close_doc " close preview if its still open after insert autocmd InsertLeave if pumvisible() == 0|pclose|endif end jedi/000077500000000000000000000000001220437504400117725ustar00rootroot00000000000000plugin/000077500000000000000000000000001220437504400123555ustar00rootroot00000000000000plugin/jedi.vim000066400000000000000000000064241220437504400140130ustar00rootroot00000000000000"jedi.vim - Omni Completion for python in vim " Maintainer: David Halter " " This part of the software is just the vim interface. The main source code " lies in the python files around it. if !has('python') && !has('python3') if !exists("g:jedi#squelch_py_warning") echomsg "Error: Required vim compiled with +python" endif finish endif " load plugin only once if exists("g:loaded_jedi") || &cp finish endif let g:loaded_jedi = 1 " ------------------------------------------------------------------------ " defaults for jedi-vim " ------------------------------------------------------------------------ let s:settings = { \ 'use_tabs_not_buffers': 1, \ 'auto_initialization': 1, \ 'auto_vim_configuration': 1, \ 'goto_command': "'g'", \ 'autocompletion_command': "''", \ 'get_definition_command': "'d'", \ 'related_names_command': "'n'", \ 'rename_command': "'r'", \ 'popup_on_dot': 1, \ 'pydoc': "'K'", \ 'show_function_definition': 1, \ 'function_definition_escape': "'≡'", \ 'auto_close_doc': 1, \ 'popup_select_first': 1, \ 'quickfix_window_height': 10 \ } for [key, val] in items(s:settings) if !exists('g:jedi#'.key) exe 'let g:jedi#'.key.' = '.val endif endfor if g:jedi#auto_vim_configuration filetype plugin on endif if g:jedi#auto_initialization " this is only here because in some cases the VIM library adds their " autocompletion as a default, which may cause problems, depending on the " order of invocation. autocmd FileType Python setlocal omnifunc=jedi#complete switchbuf=useopen " needed for pydoc endif fun! Pyimport(cmd, args) py << EOF # args are the same as for the :edit command # cmd: one of edit, split, vsplit, tabedit, ... if 1: import vim import jedi import os.path as osp from shlex import split as shsplit cmd = vim.eval('a:cmd') args = shsplit(vim.eval('a:args')) text = 'import %s' % args.pop() scr = jedi.Script(text, 1, len(text), '') try: path = scr.goto_assignments()[0].module_path except IndexError: path = None if path and osp.isfile(path): cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) vim.command('%s %s %s' % (cmd, cmd_args , path.replace(' ', '\ '))) EOF endfun fun! Pyimport_comp(argl, cmdl, pos) py << EOF if 1: import vim import re import json argl = vim.eval('a:argl') try: import jedi except ImportError as err: print('Pyimport completion requires jedi module: https://github.com/davidhalter/jedi') comps = [] else: text = 'import %s' % argl script=jedi.Script(text, 1, len(text), '') comps = ['%s%s' % (argl, c.complete) for c in script.completions()] vim.command("let comps = '%s'" % '\n'.join(comps)) EOF return comps endfun command! -nargs=1 -complete=custom,Pyimport_comp Pyimport :call Pyimport('edit', ) " command! -nargs=1 -complete=custom,Pyimport_comp Pysplit :call Pyimport('split', ) " command! -nargs=1 -complete=custom,Pyimport_comp Pyvsplit :call Pyimport('vsplit', ) " command! -nargs=1 -complete=custom,Pyimport_comp Pytabe :call Pyimport('tabe', ) " vim: set et ts=4: plugin/jedi_vim.py000066400000000000000000000313271220437504400145230ustar00rootroot00000000000000""" The Python parts of the Jedi library for VIM. It is mostly about communicating with VIM. """ import traceback # for exception output import re import os import vim import jedi import jedi.keywords from jedi._compatibility import unicode def echo_highlight(msg): vim.command('echohl WarningMsg | echom "%s" | echohl None' % msg) if not hasattr(jedi, '__version__') or jedi.__version__ < (0, 6, 0): echo_highlight('Please update your Jedi version, it is to old.') class PythonToVimStr(unicode): """ Vim has a different string implementation of single quotes """ __slots__ = [] def __repr__(self): # this is totally stupid and makes no sense but vim/python unicode # support is pretty bad. don't ask how I came up with this... It just # works... # It seems to be related to that bug: http://bugs.python.org/issue5876 if unicode is str: s = self else: s = self.encode('UTF-8') return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"') def get_script(source=None, column=None): jedi.settings.additional_dynamic_modules = [b.name for b in vim.buffers if b.name is not None and b.name.endswith('.py')] if source is None: source = '\n'.join(vim.current.buffer) row = vim.current.window.cursor[0] if column is None: column = vim.current.window.cursor[1] buf_path = vim.current.buffer.name encoding = vim.eval('&encoding') or 'latin1' return jedi.Script(source, row, column, buf_path, encoding) def complete(): row, column = vim.current.window.cursor clear_func_def() if vim.eval('a:findstart') == '1': count = 0 for char in reversed(vim.current.line[:column]): if not re.match('[\w\d]', char): break count += 1 vim.command('return %i' % (column - count)) else: base = vim.eval('a:base') source = '' for i, line in enumerate(vim.current.buffer): # enter this path again, otherwise source would be incomplete if i == row - 1: source += line[:column] + base + line[column:] else: source += line source += '\n' # here again hacks, because jedi has a different interface than vim column += len(base) try: script = get_script(source=source, column=column) completions = script.completions() sig = script.call_signatures() call_def = sig[0] if sig else None out = [] for c in completions: d = dict(word=PythonToVimStr(c.name[:len(base)] + c.complete), abbr=PythonToVimStr(c.name), # stuff directly behind the completion menu=PythonToVimStr(c.description), info=PythonToVimStr(c.doc), # docstr icase=1, # case insensitive dup=1 # allow duplicates (maybe later remove this) ) out.append(d) strout = str(out) except Exception: # print to stdout, will be in :messages print(traceback.format_exc()) strout = '' completions = [] call_def = None #print 'end', strout show_func_def(call_def, len(completions)) vim.command('return ' + strout) def goto(is_definition=False, is_related_name=False, no_output=False): definitions = [] script = get_script() try: if is_related_name: definitions = script.usages() elif is_definition: definitions = script.goto_definitions() else: definitions = script.goto_assignments() except jedi.NotFoundError: echo_highlight( "Cannot follow nothing. Put your cursor on a valid name.") except Exception: # print to stdout, will be in :messages echo_highlight("Some different eror, this shouldn't happen.") print(traceback.format_exc()) else: if no_output: return definitions if not definitions: echo_highlight("Couldn't find any definitions for this.") elif len(definitions) == 1 and not is_related_name: # just add some mark to add the current position to the jumplist. # this is ugly, because it overrides the mark for '`', so if anyone # has a better idea, let me know. vim.command('normal! m`') d = list(definitions)[0] if d.in_builtin_module(): if d.is_keyword: echo_highlight( "Cannot get the definition of Python keywords.") else: echo_highlight("Builtin modules cannot be displayed (%s)." % d.module_path) else: if d.module_path != vim.current.buffer.name: vim.eval('jedi#new_buffer(%s)' % \ repr(PythonToVimStr(d.module_path))) vim.current.window.cursor = d.line, d.column vim.command('normal! zt') # cursor at top of screen else: # multiple solutions lst = [] for d in definitions: if d.in_builtin_module(): lst.append(dict(text= PythonToVimStr('Builtin ' + d.description))) else: lst.append(dict(filename=PythonToVimStr(d.module_path), lnum=d.line, col=d.column + 1, text=PythonToVimStr(d.description))) vim.eval('setqflist(%s)' % repr(lst)) vim.eval('jedi#add_goto_window()') return definitions def show_pydoc(): script = get_script() try: definitions = script.goto_definitions() except jedi.NotFoundError: definitions = [] except Exception: # print to stdout, will be in :messages definitions = [] print("Exception, this shouldn't happen.") print(traceback.format_exc()) if not definitions: vim.command('return') else: docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc else '|No Docstring for %s|' % d for d in definitions] text = ('\n' + '-' * 79 + '\n').join(docs) vim.command('let l:doc = %s' % repr(PythonToVimStr(text))) vim.command('let l:doc_lines = %s' % len(text.split('\n'))) def clear_func_def(): cursor = vim.current.window.cursor e = vim.eval('g:jedi#function_definition_escape') regex = r'%sjedi=([0-9]+), ([^%s]*)%s.*%sjedi%s'.replace('%s', e) for i, line in enumerate(vim.current.buffer): match = re.search(r'%s' % regex, line) if match is not None: vim_regex = r'\v' + regex.replace('=', r'\=') + '.{%s}' % \ int(match.group(1)) vim.command(r'try | %s,%ss/%s/\2/g | catch | endtry' \ % (i + 1, i + 1, vim_regex)) vim.eval('histdel("search", -1)') vim.command('let @/ = histget("search", -1)') vim.current.window.cursor = cursor def show_func_def(call_def=None, completion_lines=0): if vim.eval("has('conceal') && g:jedi#show_function_definition") == '0': return try: if call_def == None: sig = get_script().call_signatures() call_def = sig[0] if sig else None clear_func_def() if call_def is None: return row, column = call_def.bracket_start if column < 1 or row == 0: return # edge cases, just ignore # TODO check if completion menu is above or below row_to_replace = row - 1 line = vim.eval("getline(%s)" % row_to_replace) insert_column = column - 1 # because there's a space before the bracket params = [p.get_code().replace('\n', '') for p in call_def.params] try: params[call_def.index] = '*%s*' % params[call_def.index] except (IndexError, TypeError): pass # This stuff is reaaaaally a hack! I cannot stress enough, that this is # a stupid solution. But there is really no other yet. There is no # possibility in VIM to draw on the screen, but there will be one (see # :help todo Patch to access screen under Python. (Marko Mahni, 2010 # Jul 18)) text = " (%s) " % ', '.join(params) text = ' ' * (insert_column - len(line)) + text end_column = insert_column + len(text) - 2 # -2 due to bold symbols # Need to decode it with utf8, because vim returns always a python 2 # string even if it is unicode. e = vim.eval('g:jedi#function_definition_escape') if hasattr(e, 'decode'): e = e.decode('UTF-8') # replace line before with cursor regex = "xjedi=%sx%sxjedix".replace('x', e) prefix, replace = line[:insert_column], line[insert_column:end_column] # Check the replace stuff for strings, to append them # (don't want to break the syntax) regex_quotes = r'''\\*["']+''' # `add` are all the quotation marks. # join them with a space to avoid producing ''' add = ' '.join(re.findall(regex_quotes, replace)) # search backwards if add and replace[0] in ['"', "'"]: a = re.search(regex_quotes + '$', prefix) add = ('' if a is None else a.group(0)) + add tup = '%s, %s' % (len(add), replace) repl = prefix + (regex % (tup, text)) + add + line[end_column:] vim.eval('setline(%s, %s)' % \ (row_to_replace, repr(PythonToVimStr(repl)))) except Exception: print(traceback.format_exc()) def rename(): if not int(vim.eval('a:0')): _rename_cursor = vim.current.window.cursor vim.command('normal A ') # otherwise startinsert doesn't work well vim.current.window.cursor = _rename_cursor vim.command('augroup jedi_rename') vim.command('autocmd InsertLeave call jedi#rename(1)') vim.command('augroup END') vim.command('normal! diw') vim.command(':startinsert') else: window_path = vim.current.buffer.name # reset autocommand vim.command('autocmd! jedi_rename InsertLeave') replace = vim.eval("expand('')") vim.command('normal! u') # undo new word cursor = vim.current.window.cursor vim.command('normal! u') # undo the space at the end vim.current.window.cursor = cursor if replace is None: echo_highlight('No rename possible, if no name is given.') else: temp_rename = goto(is_related_name=True, no_output=True) # sort the whole thing reverse (positions at the end of the line # must be first, because they move the stuff before the position). temp_rename = sorted(temp_rename, reverse=True, key=lambda x: (x.module_path, x.start_pos)) for r in temp_rename: if r.in_builtin_module(): continue if vim.current.buffer.name != r.module_path: vim.eval("jedi#new_buffer('%s')" % r.module_path) vim.current.window.cursor = r.start_pos vim.command('normal! cw%s' % replace) vim.eval("jedi#new_buffer('%s')" % window_path) vim.current.window.cursor = cursor echo_highlight('Jedi did %s renames!' % len(temp_rename)) def tabnew(path): "Open a file in a new tab or switch to an existing one" path = os.path.abspath(path) if vim.eval('has("gui")') == '1': vim.command('tab drop %s' % path) return for tab_nr in range(int(vim.eval("tabpagenr('$')"))): for buf_nr in vim.eval("tabpagebuflist(%i + 1)" % tab_nr): buf_nr = int(buf_nr) - 1 try: buf_path = vim.buffers[buf_nr].name except LookupError: # Just do good old asking for forgiveness. # don't know why this happens :-) pass else: if buf_path == path: # tab exists, just switch to that tab vim.command('tabfirst | tabnext %i' % (tab_nr + 1)) break else: continue break else: # tab doesn't exist, add a new one. vim.command('tabnew %s' % path) def escape_file_path(path): return path.replace(' ', r'\ ') def print_to_stdout(level, str_out): print(str_out)