pymode.vim 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. let g:pymode_version = "0.6.9"
  2. com! PymodeVersion echomsg "Current python-mode version: " . g:pymode_version
  3. " OPTION: g:pymode -- bool. Run pymode.
  4. if pymode#Default('g:pymode', 1) || !g:pymode
  5. " DESC: Disable script loading
  6. finish
  7. endif
  8. " DESC: Check python support
  9. if !has('python')
  10. echoerr expand("<sfile>:t") . " required vim compiled with +python."
  11. let g:pymode_lint = 0
  12. let g:pymode_rope = 0
  13. let g:pymode_path = 0
  14. let g:pymode_doc = 0
  15. let g:pymode_run = 0
  16. let g:pymode_virtualenv = 0
  17. endif
  18. " Virtualenv {{{
  19. if !pymode#Default("g:pymode_virtualenv", 1) || g:pymode_virtualenv
  20. call pymode#Default("g:pymode_virtualenv_enabled", [])
  21. " Add virtualenv paths
  22. call pymode#virtualenv#Activate()
  23. endif
  24. " }}}
  25. " DESC: Fix python path
  26. if !pymode#Default('g:pymode_path', 1) || g:pymode_path
  27. call pymode#Default('g:pymode_paths', [])
  28. python << EOF
  29. import sys, vim, os
  30. curpath = vim.eval("getcwd()")
  31. libpath = os.path.join(os.path.dirname(os.path.dirname(
  32. vim.eval("expand('<sfile>:p')"))), 'pylibs')
  33. sys.path = [os.path.dirname(libpath), libpath, curpath] + vim.eval("g:pymode_paths") + sys.path
  34. EOF
  35. endif
  36. " Lint {{{
  37. if !pymode#Default("g:pymode_lint", 1) || g:pymode_lint
  38. let g:qf_list = []
  39. let g:pymode_lint_buffer = 0
  40. " OPTION: g:pymode_lint_write -- bool. Check code every save.
  41. call pymode#Default("g:pymode_lint_write", 1)
  42. " OPTION: g:pymode_lint_onfly -- bool. Check code every save.
  43. call pymode#Default("g:pymode_lint_onfly", 0)
  44. " OPTION: g:pymode_lint_message -- bool. Show current line error message
  45. call pymode#Default("g:pymode_lint_message", 1)
  46. " OPTION: g:pymode_lint_checker -- str. Choices are: pylint, pyflakes, pep8, mccabe
  47. call pymode#Default("g:pymode_lint_checker", "pyflakes,pep8,mccabe")
  48. " OPTION: g:pymode_lint_config -- str. Path to pylint config file
  49. call pymode#Default("g:pymode_lint_config", $HOME . "/.pylintrc")
  50. " OPTION: g:pymode_lint_cwindow -- bool. Auto open cwindow if errors find
  51. call pymode#Default("g:pymode_lint_cwindow", 1)
  52. " OPTION: g:pymode_lint_jump -- int. Jump on first error.
  53. call pymode#Default("g:pymode_lint_jump", 0)
  54. " OPTION: g:pymode_lint_hold -- int. Hold cursor on current window when
  55. " quickfix open
  56. call pymode#Default("g:pymode_lint_hold", 0)
  57. " OPTION: g:pymode_lint_minheight -- int. Minimal height of pymode lint window
  58. call pymode#Default("g:pymode_lint_minheight", 3)
  59. " OPTION: g:pymode_lint_maxheight -- int. Maximal height of pymode lint window
  60. call pymode#Default("g:pymode_lint_maxheight", 6)
  61. " OPTION: g:pymode_lint_ignore -- string. Skip errors and warnings (e.g. E4,W)
  62. call pymode#Default("g:pymode_lint_ignore", "E501")
  63. " OPTION: g:pymode_lint_select -- string. Select errors and warnings (e.g. E4,W)
  64. call pymode#Default("g:pymode_lint_select", "")
  65. " OPTION: g:pymode_lint_mccabe_complexity -- int. Maximum allowed complexity
  66. call pymode#Default("g:pymode_lint_mccabe_complexity", 8)
  67. " OPTION: g:pymode_lint_signs_always_visible -- bool. Always show the
  68. " errors ruller, even if there's no errors.
  69. call pymode#Default("g:pymode_lint_signs_always_visible", 0)
  70. " OPTION: g:pymode_lint_signs -- bool. Place error signs
  71. if (!pymode#Default("g:pymode_lint_signs", 1) || g:pymode_lint_signs) && has('signs')
  72. " DESC: Signs definition
  73. sign define W text=WW texthl=Todo
  74. sign define C text=CC texthl=Comment
  75. sign define R text=RR texthl=Visual
  76. sign define E text=EE texthl=Error
  77. sign define I text=II texthl=Info
  78. if !pymode#Default("g:pymode_lint_signs_always_visible", 0) || g:pymode_lint_signs_always_visible
  79. " Show the sign's ruller if asked for, even it there's no error to show
  80. sign define __dummy__
  81. autocmd BufRead,BufNew * call RopeShowSignsRulerIfNeeded()
  82. endif
  83. endif
  84. " DESC: Set default pylint configuration
  85. if !filereadable(g:pymode_lint_config)
  86. let g:pymode_lint_config = expand("<sfile>:p:h:h") . "/pylint.ini"
  87. endif
  88. py from pymode import lint, queue, auto
  89. au VimLeavePre * py queue.stop_queue()
  90. endif
  91. " }}}
  92. " Documentation {{{
  93. if !pymode#Default("g:pymode_doc", 1) || g:pymode_doc
  94. " OPTION: g:pymode_doc_key -- string. Key for show python documantation.
  95. call pymode#Default("g:pymode_doc_key", "K")
  96. endif
  97. " }}}
  98. " Breakpoints {{{
  99. if !pymode#Default("g:pymode_breakpoint", 1) || g:pymode_breakpoint
  100. if !pymode#Default("g:pymode_breakpoint_cmd", "import ipdb; ipdb.set_trace() ### XXX BREAKPOINT") && has("python")
  101. python << EOF
  102. from imp import find_module
  103. try:
  104. find_module('ipdb')
  105. except ImportError:
  106. vim.command('let g:pymode_breakpoint_cmd = "import pdb; pdb.set_trace() ### XXX BREAKPOINT"')
  107. EOF
  108. endif
  109. " OPTION: g:pymode_breakpoint_key -- string. Key for set/unset breakpoint.
  110. call pymode#Default("g:pymode_breakpoint_key", "<leader>b")
  111. endif
  112. " }}}
  113. " Execution {{{
  114. if !pymode#Default("g:pymode_run", 1) || g:pymode_run
  115. " OPTION: g:pymode_doc_key -- string. Key for show python documentation.
  116. call pymode#Default("g:pymode_run_key", "<leader>r")
  117. endif
  118. " }}}
  119. " Rope {{{
  120. if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
  121. " OPTION: g:pymode_rope_auto_project -- bool. Auto create ropeproject
  122. call pymode#Default("g:pymode_rope_auto_project", 1)
  123. " OPTION: g:pymode_rope_auto_project_open -- bool.
  124. " Auto open existing projects, ie, if the current directory has a
  125. " `.ropeproject` subdirectory.
  126. call pymode#Default("g:pymode_rope_auto_project_open", 1)
  127. " OPTION: g:pymode_rope_auto_session_manage -- bool
  128. call pymode#Default("g:pymode_rope_auto_session_manage", 0)
  129. " OPTION: g:pymode_rope_enable_autoimport -- bool. Enable autoimport
  130. call pymode#Default("g:pymode_rope_enable_autoimport", 1)
  131. " OPTION: g:pymode_rope_autoimport_generate -- bool.
  132. call pymode#Default("g:pymode_rope_autoimport_generate", 1)
  133. " OPTION: g:pymode_rope_autoimport_underlines -- bool.
  134. call pymode#Default("g:pymode_rope_autoimport_underlineds", 0)
  135. " OPTION: g:pymode_rope_codeassist_maxfiles -- bool.
  136. call pymode#Default("g:pymode_rope_codeassist_maxfixes", 10)
  137. " OPTION: g:pymode_rope_sorted_completions -- bool.
  138. call pymode#Default("g:pymode_rope_sorted_completions", 1)
  139. " OPTION: g:pymode_rope_extended_complete -- bool.
  140. call pymode#Default("g:pymode_rope_extended_complete", 1)
  141. " OPTION: g:pymode_rope_autoimport_modules -- array.
  142. call pymode#Default("g:pymode_rope_autoimport_modules", ["os","shutil","datetime"])
  143. " OPTION: g:pymode_rope_confirm_saving -- bool.
  144. call pymode#Default("g:pymode_rope_confirm_saving", 1)
  145. " OPTION: g:pymode_rope_global_prefix -- string.
  146. call pymode#Default("g:pymode_rope_global_prefix", "<C-x>p")
  147. " OPTION: g:pymode_rope_local_prefix -- string.
  148. call pymode#Default("g:pymode_rope_local_prefix", "<C-c>r")
  149. " OPTION: g:pymode_rope_short_prefix -- string.
  150. call pymode#Default("g:pymode_rope_short_prefix", "<C-c>")
  151. " OPTION: g:pymode_rope_map_space -- string.
  152. call pymode#Default("g:pymode_rope_map_space", 1)
  153. " OPTION: g:pymode_rope_vim_completion -- bool.
  154. call pymode#Default("g:pymode_rope_vim_completion", 1)
  155. " OPTION: g:pymode_rope_guess_project -- bool.
  156. call pymode#Default("g:pymode_rope_guess_project", 1)
  157. " OPTION: g:pymode_rope_goto_def_newwin -- str ('new', 'vnew', '').
  158. call pymode#Default("g:pymode_rope_goto_def_newwin", "")
  159. " OPTION: g:pymode_rope_always_show_complete_menu -- bool.
  160. call pymode#Default("g:pymode_rope_always_show_complete_menu", 0)
  161. " DESC: Init Rope
  162. py import ropevim
  163. fun! RopeCodeAssistInsertMode() "{{{
  164. call RopeCodeAssist()
  165. return ""
  166. endfunction "}}}
  167. fun! RopeOpenExistingProject() "{{{
  168. if isdirectory(getcwd() . '/.ropeproject')
  169. " In order to pass it the quiet kwarg I need to open the project
  170. " using python and not vim, which should be no major issue
  171. py ropevim._interface.open_project(quiet=True)
  172. return ""
  173. endif
  174. endfunction "}}}
  175. fun! RopeLuckyAssistInsertMode() "{{{
  176. call RopeLuckyAssist()
  177. return ""
  178. endfunction "}}}
  179. fun! RopeOmni(findstart, base) "{{{
  180. if a:findstart
  181. py ropevim._interface._find_start()
  182. return g:pymode_offset
  183. else
  184. call RopeOmniComplete()
  185. return g:pythoncomplete_completions
  186. endif
  187. endfunction "}}}
  188. fun! RopeShowSignsRulerIfNeeded() "{{{
  189. if &ft == 'python'
  190. execute printf('silent! sign place 1 line=1 name=__dummy__ file=%s', expand("%:p"))
  191. endif
  192. endfunction "}}}
  193. " Rope menu
  194. menu <silent> Rope.Autoimport :RopeAutoImport<CR>
  195. menu <silent> Rope.ChangeSignature :RopeChangeSignature<CR>
  196. menu <silent> Rope.CloseProject :RopeCloseProject<CR>
  197. menu <silent> Rope.GenerateAutoImportCache :RopeGenerateAutoimportCache<CR>
  198. menu <silent> Rope.ExtractVariable :RopeExtractVariable<CR>
  199. menu <silent> Rope.ExtractMethod :RopeExtractMethod<CR>
  200. menu <silent> Rope.Inline :RopeInline<CR>
  201. menu <silent> Rope.IntroduceFactory :RopeIntroduceFactory<CR>
  202. menu <silent> Rope.FindFile :RopeFindFile<CR>
  203. menu <silent> Rope.OpenProject :RopeOpenProject<CR>
  204. menu <silent> Rope.Move :RopeMove<CR>
  205. menu <silent> Rope.MoveCurrentModule :RopeMoveCurrentModule<CR>
  206. menu <silent> Rope.ModuleToPackage :RopeModuleToPackage<CR>
  207. menu <silent> Rope.Redo :RopeRedo<CR>
  208. menu <silent> Rope.Rename :RopeRename<CR>
  209. menu <silent> Rope.RenameCurrentModule :RopeRenameCurrentModule<CR>
  210. menu <silent> Rope.Restructure :RopeRestructure<CR>
  211. menu <silent> Rope.Undo :RopeUndo<CR>
  212. menu <silent> Rope.UseFunction :RopeUseFunction<CR>
  213. if !pymode#Default("g:pymode_rope_auto_project_open", 1) || g:pymode_rope_auto_project_open
  214. call RopeOpenExistingProject()
  215. endif
  216. if !pymode#Default("g:pymode_rope_auto_session_manage", 0) || g:pymode_rope_auto_session_manage
  217. autocmd VimLeave * call RopeSaveSession()
  218. autocmd VimEnter * call RopeRestoreSession()
  219. endif
  220. endif
  221. " }}}
  222. " OPTION: g:pymode_folding -- bool. Enable python-mode folding for pyfiles.
  223. call pymode#Default("g:pymode_folding", 1)
  224. " OPTION: g:pymode_syntax -- bool. Enable python-mode syntax for pyfiles.
  225. call pymode#Default("g:pymode_syntax", 1)
  226. " OPTION: g:pymode_indent -- bool. Enable/Disable pymode PEP8 indentation
  227. call pymode#Default("g:pymode_indent", 1)
  228. " OPTION: g:pymode_utils_whitespaces -- bool. Remove unused whitespaces on save
  229. call pymode#Default("g:pymode_utils_whitespaces", 1)
  230. " OPTION: g:pymode_options -- bool. To set some python options.
  231. call pymode#Default("g:pymode_options", 1)
  232. " OPTION: g:pymode_updatetime -- int. Set updatetime for async pymode's operation
  233. call pymode#Default("g:pymode_updatetime", 1000)
  234. " vim: fdm=marker:fdl=0