lint.vim 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. fun! pymode#lint#Check() "{{{
  2. " DESC: Run checkers on current file.
  3. "
  4. if !g:pymode_lint | return | endif
  5. if &modifiable && &modified
  6. try
  7. write
  8. catch /E212/
  9. echohl Error | echo "File modified and I can't save it. Cancel code checking." | echohl None
  10. return 0
  11. endtry
  12. endif
  13. let g:pymode_lint_buffer = bufnr('%')
  14. py lint.check_file()
  15. endfunction " }}}
  16. fun! pymode#lint#Parse()
  17. " DESC: Parse result of code checking.
  18. "
  19. call setqflist(g:qf_list, 'r')
  20. if g:pymode_lint_signs
  21. call pymode#PlaceSigns()
  22. endif
  23. if g:pymode_lint_cwindow
  24. call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, g:pymode_lint_jump)
  25. endif
  26. if !len(g:qf_list)
  27. call pymode#WideMessage('Code checking is completed. No errors found.')
  28. endif
  29. endfunction
  30. fun! pymode#lint#Toggle() "{{{
  31. let g:pymode_lint = g:pymode_lint ? 0 : 1
  32. call pymode#lint#toggle_win(g:pymode_lint, "Pymode lint")
  33. endfunction "}}}
  34. fun! pymode#lint#ToggleWindow() "{{{
  35. let g:pymode_lint_cwindow = g:pymode_lint_cwindow ? 0 : 1
  36. call pymode#lint#toggle_win(g:pymode_lint_cwindow, "Pymode lint cwindow")
  37. endfunction "}}}
  38. fun! pymode#lint#ToggleChecker() "{{{
  39. let g:pymode_lint_checker = g:pymode_lint_checker == "pylint" ? "pyflakes" : "pylint"
  40. echomsg "Pymode lint checker: " . g:pymode_lint_checker
  41. endfunction "}}}
  42. fun! pymode#lint#toggle_win(toggle, msg) "{{{
  43. if a:toggle
  44. echomsg a:msg." enabled"
  45. botright cwindow
  46. if &buftype == "quickfix"
  47. wincmd p
  48. endif
  49. else
  50. echomsg a:msg." disabled"
  51. cclose
  52. endif
  53. endfunction "}}}
  54. fun! pymode#lint#show_errormessage() "{{{
  55. if g:pymode_lint_buffer != bufnr('%')
  56. return 0
  57. endif
  58. let errors = getqflist()
  59. if !len(errors)
  60. return
  61. endif
  62. let [_, line, _, _] = getpos(".")
  63. for e in errors
  64. if e['lnum'] == line
  65. call pymode#WideMessage(e['text'])
  66. else
  67. echo
  68. endif
  69. endfor
  70. endfunction " }}}
  71. fun! pymode#lint#Auto() "{{{
  72. if &modifiable && &modified
  73. try
  74. write
  75. catch /E212/
  76. echohl Error | echo "File modified and I can't save it. Cancel operation." | echohl None
  77. return 0
  78. endtry
  79. endif
  80. py auto.fix_current_file()
  81. cclose
  82. edit
  83. endfunction "}}}