My dotfiles. Period.

python_flake8.vim 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "
  2. " Python filetype plugin for running flake8
  3. " Language: Python (ft=python)
  4. " Maintainer: Vincent Driessen <vincent@3rdcloud.com>
  5. " Version: Vim 7 (may work with lower Vim versions, but not tested)
  6. " URL: http://github.com/nvie/vim-flake8
  7. "
  8. " Only do this when not done yet for this buffer
  9. if exists("b:loaded_flake8_ftplugin")
  10. finish
  11. endif
  12. let b:loaded_flake8_ftplugin=1
  13. if !exists("*Flake8()")
  14. function Flake8()
  15. if exists("g:flake8_cmd")
  16. let s:flake8_cmd=g:flake8_cmd
  17. else
  18. let s:flake8_cmd="flake8"
  19. endif
  20. if !executable(s:flake8_cmd)
  21. echoerr "File " . s:flake8_cmd . " not found. Please install it first."
  22. return
  23. endif
  24. set lazyredraw " delay redrawing
  25. cclose " close any existing cwindows
  26. " store old grep settings (to restore later)
  27. let l:old_gfm=&grepformat
  28. let l:old_gp=&grepprg
  29. " write any changes before continuing
  30. if &readonly == 0
  31. update
  32. endif
  33. " read config
  34. if exists("g:flake8_builtins")
  35. let s:flake8_builtins_opt=" --builtins=".g:flake8_builtins
  36. else
  37. let s:flake8_builtins_opt=""
  38. endif
  39. if exists("g:flake8_ignore")
  40. let s:flake8_ignores=" --ignore=".g:flake8_ignore
  41. else
  42. let s:flake8_ignores=""
  43. endif
  44. if exists("g:flake8_max_line_length")
  45. let s:flake8_max_line_length=" --max-line-length=".g:flake8_max_line_length
  46. else
  47. let s:flake8_max_line_length=""
  48. endif
  49. if exists("g:flake8_max_complexity")
  50. let s:flake8_max_complexity=" --max-complexity=".g:flake8_max_complexity
  51. else
  52. let s:flake8_max_complexity=""
  53. endif
  54. " perform the grep itself
  55. let &grepformat="%f:%l:%c: %m\,%f:%l: %m"
  56. let &grepprg=s:flake8_cmd.s:flake8_builtins_opt.s:flake8_ignores.s:flake8_max_line_length.s:flake8_max_complexity
  57. silent! grep! %
  58. " restore grep settings
  59. let &grepformat=l:old_gfm
  60. let &grepprg=l:old_gp
  61. " open cwindow
  62. let has_results=getqflist() != []
  63. if has_results
  64. execute 'belowright copen'
  65. setlocal wrap
  66. nnoremap <buffer> <silent> c :cclose<CR>
  67. nnoremap <buffer> <silent> q :cclose<CR>
  68. endif
  69. set nolazyredraw
  70. redraw!
  71. if has_results == 0
  72. " Show OK status
  73. hi Green ctermfg=green
  74. echohl Green
  75. echon "Flake8 check OK"
  76. echohl
  77. endif
  78. endfunction
  79. endif
  80. " Add mappings, unless the user didn't want this.
  81. " The default mapping is registered under to <F7> by default, unless the user
  82. " remapped it already (or a mapping exists already for <F7>)
  83. if !exists("no_plugin_maps") && !exists("no_flake8_maps")
  84. if !hasmapto('Flake8(')
  85. noremap <buffer> <F7> :call Flake8()<CR>
  86. endif
  87. endif