Advertisement
Guest User

spupy

a guest
Jan 30th, 2010
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. " Installation:
  2. " Drop pep8.vim in ~/.vim/compiler directory. Ensure that your PATH
  3. " environment variable includes the path to 'pep8' executable.
  4. "
  5. " Add the following line to the autocmd section of .vimrc
  6. "
  7. " autocmd FileType python compiler pep8
  8. "
  9. " Usage:
  10. " pep8 is called after a buffer with Python code is saved. QuickFix
  11. " window is opened to show errors, warnings and hints provided by pep8.
  12. "
  13. " Above is realized with :pep8 command. To disable calling pep8 every
  14. " time a buffer is saved put into .vimrc file
  15. "
  16. " let g:pep8_onwrite = 0
  17. "
  18. " Displaying code rate calculated by pep8 can be avoided by setting
  19. "
  20. " let g:pep8_show_rate = 0
  21. "
  22. " Openning of QuickFix window can be disabled with
  23. "
  24. " let g:pep8_cwindow = 0
  25. "
  26. " Of course, standard :make command can be used as in case of every
  27. " other compiler.
  28. "
  29.  
  30.  
  31. if exists('current_compiler')
  32. finish
  33. endif
  34. let current_compiler = 'pep8'
  35.  
  36. if !exists('g:pep8_onwrite')
  37. let g:pep8_onwrite = 1
  38. endif
  39.  
  40. if !exists('g:pep8_show_rate')
  41. let g:pep8_show_rate = 1
  42. endif
  43.  
  44. if !exists('g:pep8_cwindow')
  45. let g:pep8_cwindow = 1
  46. endif
  47.  
  48. if exists(':Pep8') != 2
  49. command Pep8 :call Pep8(0)
  50. endif
  51.  
  52. if exists(":CompilerSet") != 2 " older Vim always used :setlocal
  53. command -nargs=* CompilerSet setlocal <args>
  54. endif
  55.  
  56. CompilerSet makeprg=(echo\ '[%]';\ pep8\ %)
  57.  
  58. " We could omit end of file-entry, there is only one file
  59. " %+I... - include code rating information
  60. " %-G... - remove all remaining report lines from quickfix buffer
  61. CompilerSet efm=%f:%l:%c:\ %m
  62.  
  63. if g:pep8_onwrite
  64. augroup python
  65. au!
  66. au BufWritePost * call Pep8(1)
  67. augroup end
  68. endif
  69.  
  70. function! Pep8(writing)
  71. if !a:writing && &modified
  72. " Save before running
  73. write
  74. endif
  75.  
  76. if has('win32') || has('win16') || has('win95') || has('win64')
  77. setlocal sp=>%s
  78. else
  79. setlocal sp=>%s\ 2>&1
  80. endif
  81.  
  82. " If check is executed by buffer write - do not jump to first error
  83. if !a:writing
  84. silent make
  85. else
  86. silent make!
  87. endif
  88.  
  89. if g:pep8_cwindow
  90. cwindow
  91. endif
  92.  
  93. call Pep8Evaluation()
  94.  
  95. if g:pep8_show_rate
  96. echon 'code rate: ' b:pep8_rate ', prev: ' b:pep8_prev_rate
  97. endif
  98. endfunction
  99.  
  100. function! Pep8Evaluation()
  101. let l:list = getqflist()
  102. let b:pep8_rate = '0.00'
  103. let b:pep8_prev_rate = '0.00'
  104. for l:item in l:list
  105. if l:item.type == 'I' && l:item.text =~ 'Your code has been rated'
  106. let l:re_rate = '\(-\?[0-9]\{1,2\}\.[0-9]\{2\}\)/'
  107. let b:pep8_rate = substitute(l:item.text, '.*rated at '.l:re_rate.'.*', '\1', 'g')
  108. " Only if there is information about previous run
  109. if l:item.text =~ 'previous run: '
  110. let b:pep8_prev_rate = substitute(l:item.text, '.*previous run: '.l:re_rate.'.*', '\1', 'g')
  111. endif
  112. endif
  113. endfor
  114. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement