diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2022-05-03 02:36:08 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2022-05-03 02:36:08 +1200 |
commit | 005bad1031f6e76dd38171296b820643a8f5576c (patch) | |
tree | 5524de49e78f5fe98cdc5bbba71270689fda5edc | |
parent | Highlight jinja2 files with Django's rules (diff) | |
download | dotfiles-005bad1031f6e76dd38171296b820643a8f5576c.tar.gz dotfiles-005bad1031f6e76dd38171296b820643a8f5576c.zip |
Add checking, tidying, and linting for Python
-rw-r--r-- | vim/after/ftplugin/python.vim | 27 | ||||
-rw-r--r-- | vim/compiler/pyflakes.vim | 9 | ||||
-rw-r--r-- | vim/compiler/pylint.vim | 9 |
3 files changed, 45 insertions, 0 deletions
diff --git a/vim/after/ftplugin/python.vim b/vim/after/ftplugin/python.vim new file mode 100644 index 00000000..b5071e3b --- /dev/null +++ b/vim/after/ftplugin/python.vim @@ -0,0 +1,27 @@ +" Use pyflakes for syntax checking and autopep8 for tidying +compiler pyflakes +if executable('autopep8') + setlocal equalprg=autopep8\ -aaa\ --\ - + let b:undo_ftplugin .= '|setlocal equalprg<' +endif + +" Stop here if the user doesn't want ftplugin mappings +if exists('no_plugin_maps') || exists('no_python_maps') + finish +endif + +" Mappings to choose compiler +nnoremap <buffer> <LocalLeader>c + \ :<C-U>compiler pyflakes<CR> +nnoremap <buffer> <LocalLeader>l + \ :<C-U>compiler pylint<CR> +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>c' + \ . '|nunmap <buffer> <LocalLeader>l' + +" Mappings to choose 'equalprg' +nnoremap <buffer> <LocalLeader>t + \ :<C-U>setlocal equalprg=equalprg=autopep8\ -aaa\ --\ -<CR> +nnoremap <buffer> <LocalLeader>i + \ :<C-U>setlocal equalprg<<CR> +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>t' + \ . '|nunmap <buffer> <LocalLeader>i' diff --git a/vim/compiler/pyflakes.vim b/vim/compiler/pyflakes.vim new file mode 100644 index 00000000..727fbd76 --- /dev/null +++ b/vim/compiler/pyflakes.vim @@ -0,0 +1,9 @@ +" :compiler support for Python syntax checking with pyflakes +" <https://pypi.org/project/pyflakes/> +if exists('current_compiler') || &compatible || !has('patch-7.4.191') + finish +endif +let current_compiler = 'pyflakes' + +CompilerSet makeprg=pyflakes\ %:S +CompilerSet errorformat=%f:%l:%c:\ %m diff --git a/vim/compiler/pylint.vim b/vim/compiler/pylint.vim new file mode 100644 index 00000000..589f78e3 --- /dev/null +++ b/vim/compiler/pylint.vim @@ -0,0 +1,9 @@ +" :compiler support for Python linting with pylint +" <https://pypi.org/project/pyflakes/> +if exists('current_compiler') || &compatible || !has('patch-7.4.191') + finish +endif +let current_compiler = 'pylint' + +CompilerSet makeprg=pylint\ --output-format=parseable\ --score=n\ %:S +CompilerSet errorformat=%f:%l:\ %m |