Permalink
Browse files

Added Jedi

  • Loading branch information...
1 parent 624c2df commit 344308380a3e908f1befe08bd5d968037cda2e62 @robertmeta committed Nov 3, 2012
Showing with 827 additions and 226 deletions.
  1. +4 −3 .vimrc
  2. +34 −0 after/syntax/python.vim
  3. +167 −0 autoload/jedi.vim
  4. +50 −71 doc/NERD_commenter.txt
  5. +32 −0 ftplugin/python/jedi.vim
  6. +175 −152 plugin/NERD_commenter.vim
  7. +74 −0 plugin/jedi.vim
  8. +291 −0 plugin/jedi_vim.py
  9. BIN plugin/jedi_vim.pyc
View
7 .vimrc
@@ -32,7 +32,7 @@
" }}}
" Newish {{{
set history=9999 " big old history
- set timeoutlen=400 " super low delay (works for me)
+ set timeoutlen=300 " super low delay (works for me)
set formatoptions+=n " Recognize numbered lists
set formatlistpat=^\\s*\\(\\d\\\|[-*]\\)\\+[\\]:.)}\\t\ ]\\s* "and bullets, too
set viminfo+=! " Store upper-case registers in viminfo
@@ -111,7 +111,7 @@
" +-- full path to file in the buffer
" }}}
" Text Formatting/Layout {{{
- set completeopt= " don't use a pop up menu for completions
+ set completeopt=menuone " don't use a pop up menu for completions
set expandtab " no real tabs please!
set formatoptions=rq " Automatically insert comment leader on return, and let gq format comments
set ignorecase " case insensitive by default
@@ -157,6 +157,8 @@
let NERDChristmasTree = 1
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 0
+
+ let g:jedi#use_tabs_not_buffers = 1
" }}}
" Mappings {{{
" hit f11 to paste
@@ -240,5 +242,4 @@ endif
" Odds n Ends {{{
hi Folded ctermbg=black guibg=black
set ttymouse=xterm2 " makes it work in everything
- match ErrorMsg '\%>120v.\+'
" }}}
View
@@ -0,0 +1,34 @@
+if 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
View
@@ -0,0 +1,167 @@
+" ------------------------------------------------------------------------
+" 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
+
+
+" ------------------------------------------------------------------------
+" show_pydoc
+" ------------------------------------------------------------------------
+function! jedi#show_pydoc()
+python << PYTHONEOF
+if 1:
+ script = jedi_vim.get_script()
+ try:
+ definitions = script.get_definition()
+ except jedi_vim.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(jedi_vim.PythonToVimStr(text)))
+ vim.command('let l:doc_lines = %s' % len(text.split('\n')))
+PYTHONEOF
+ 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 <buffer> q ZQ
+ nnoremap <buffer> 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(vim.eval('a:path'))
+ else
+ if !&hidden && &modified
+ w
+ endif
+ execute 'edit '.a:path
+ endif
+endfunction
+
+function! s:add_goto_window()
+ set lazyredraw
+ cclose
+ execute 'belowright copen 3'
+ set nolazyredraw
+ if g:jedi#use_tabs_not_buffers == 1
+ map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
+ endif
+ au WinLeave <buffer> 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
+ python jedi_vim.tabnew(vim.eval("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 <buffer> python jedi_vim.clear_func_def()
+ autocmd CursorMovedI <buffer> call jedi#show_func_def()
+endfunction
Oops, something went wrong.

0 comments on commit 3443083

Please sign in to comment.