]> Sergey Matveev's repositories - dotfiles.git/blobdiff - vim/.vim/autoload/python/lint.vim
Vim scripts refactoring
[dotfiles.git] / vim / .vim / autoload / python / lint.vim
similarity index 74%
rename from vim/.vim/ftplugin/python/pylint.vim
rename to vim/.vim/autoload/python/lint.vim
index f0dd0a7ac0a3387e7368dfa0fa64d3f01699e669..dade81ef5cf92a8ff58d202eae6d848543867e73 100644 (file)
@@ -4,7 +4,6 @@
 "
 " This plugin allows you to asynchronously call pylint.
 "
-" * Add %{LintStatus()} to your statusline to see if pylint is running
 " * Press <F6> to start pylint on current file
 " * Press <S-F6> to open quickfix window with messages from pylint
 " * All lines with corresponding pylint existing warning will be highlighted
 "   Start pylint manually (<F6>) to force its filling
 " * After Python file is saved, pylint is automatically started
 
-if exists('g:loaded_pylint') | finish | endif
-let g:loaded_pylint = 1
-
-function! LintStatus()
-    if exists("b:lint_job") && job_status(b:lint_job) == "run" | return "LN" | endif
+function! python#lint#status()
+    if exists("b:pylint_job") && job_status(b:pylint_job) == "run" | return "LN" | endif
     return ""
 endfunction
 
-function! s:qffill(ch)
+function! s:qffill(ch) abort
     let msgs = []
     while ch_status(a:ch) == 'buffered'
         let msgs = add(msgs, ch_read(a:ch))
@@ -31,7 +27,7 @@ endfunction
 
 sign define LN text=LN texthl=Error
 
-function! PylintFinish(ch)
+function! python#lint#finish(ch) abort
     let l:errorformat_bak = &errorformat
     set errorformat=%f:%l:\ [%t]%m,%f:%l:%m
     call s:qffill(a:ch)
@@ -50,8 +46,10 @@ function! PylintFinish(ch)
     endif
 endfunction
 
-function! PylintStart()
-    if exists("g:pylint_disable") || (exists("b:lint_job") && job_status(b:lint_job) == "run")
+function! python#lint#start() abort
+    if exists("g:pylint_disable") ||
+        \ (exists("b:pylint_job") &&
+        \ job_status(b:pylint_job) == "run")
         return
     endif
     let ignores = [
@@ -67,8 +65,8 @@ function! PylintStart()
         \"too-many-public-methods",
         \"no-value-for-parameter",
     \]
-    if !exists("g:pylint_linter") | let g:pylint_linter = "pylint" | endif
-    if g:pylint_linter == "flake8"
+    let linter = get(g:, "pylint_linter", "pylint")
+    if linter == "flake8"
         let cmdline = [
             \"flake8",
             \"--ignore=E501",
@@ -76,7 +74,7 @@ function! PylintStart()
             \"--max-line-length=90",
             \expand("%p")
         \]
-    elseif g:pylint_linter == "pylint"
+    elseif linter == "pylint"
         let cmdline = [
             \"pylint",
             \"--jobs=4",
@@ -91,9 +89,6 @@ function! PylintStart()
         echohl WarningMsg | echomsg "Unknown linter specified" | echohl None
         return
     endif
-    let b:lint_job = job_start(cmdline, {"in_mode": "nl",  "err_io": "null", "close_cb": "PylintFinish"})
-endfunction()
-
-map <F6> :unlet! g:pylint_disable<CR>:call PylintStart()<CR>
-map \e[32~ :redraw!<CR>:copen<CR>
-autocmd BufWritePost *.py call PylintStart()
+    let b:pylint_job = job_start(cmdline,
+        \ {"in_mode": "nl",  "err_io": "null", "close_cb": "python#lint#finish"})
+endfunction