commit 4c575a1f069252bf039c9ab88b66f4461ede25c5 Author: gryf Date: Sat Dec 10 18:31:26 2016 +0100 Initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a922839 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2016, Roman Dobosz at al. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the organization nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL ROMAN DOBOSZ BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..86dfa4b --- /dev/null +++ b/README.rst @@ -0,0 +1,40 @@ +Pep8-vim +======== + +This is simple vim plugin, which provide command ``:Pep8`` which check for PEP8_ +rules on python code in current buffer. + +Unlike any other available *vim-pep8* plugins, it doesn't parse output of +``pep8`` command line tool, but relies on ``pep8`` module, therefore ``pep8`` +has to be present in the system using system package manager or ``pip``. + +Although usable, this plugin is kind of deprecated in favor of pluggable +validators like Syntastic_. + +Installation +------------ + +To use this plugin either ``+python`` or ``+python3`` feature compiled in vim is +required. To check it, issue ``:version`` in vim instance and look for python +entries. + +To install it, any kind of Vim package manager can be used, like NeoBundle_, +Pathogen_, Vundle_ or vim-plug_. + +For manual installation, copy subdirectories from this repository to your +``~/.vim`` directory. + +Now you'll have new command ``:Pep8`` which in case of any ``PEP8`` violation +will display quickfix window with appropriate errors. + +License +------- + +This work is licensed on 3-clause BSD license. See LICENSE file for details. + +.. _Pathogen: https://github.com/tpope/vim-pathogen +.. _Vundle: https://github.com/gmarik/Vundle.vim +.. _NeoBundle: https://github.com/Shougo/neobundle.vim +.. _vim-plug: https://github.com/junegunn/vim-plug +.. _PEP8: https://www.python.org/dev/peps/pep-0008 +.. _Syntastic: https://github.com/vim-syntastic/syntastic diff --git a/ftplugin/python/pep8_fn.vim b/ftplugin/python/pep8_fn.vim new file mode 100644 index 0000000..8725ca6 --- /dev/null +++ b/ftplugin/python/pep8_fn.vim @@ -0,0 +1,153 @@ +" File: pep8_fn.vim +" Author: Roman 'gryf' Dobosz (gryf73 at gmail.com) +" Version: 1.1 +" Last Modified: 2010-09-12 +" Description: {{{ +" +" Overview +" -------- +" This plugin provides functionality to static checks for python files +" regarding PEP8 guidance[1] as ":Pep8" command. +" +" This function does not use pep8[2] command line utility, but relies on pep8 +" module. +" +" This script uses python, therefore VIm should be compiled with python +" support. You can check it by issuing ":version" command, and search for +" "+python" inside features list. +" +" Couple of ideas was taken from pyflakes.vim[3] plugin. +" +" Installation +" ------------ +" 1. Copy the pep8_fn.vim file to the $HOME/.vim/ftplugin/python or +" $HOME/vimfiles/ftplugin/python or $VIM/vimfiles/ftplugin/python +" directory. If python directory doesn't exists, it should be created. +" Refer to the following Vim help topics for more information about Vim +" plugins: +" :help add-plugin +" :help add-global-plugin +" :help runtimepath +" 2. It should be possible to import pep8 from python interpreter (it should +" report no error): +" >>> import pep8 +" >>> +" If there are errors, install pep8 first. Simplest way to do it, is to +" use easy_install[4] shell command as a root: +" # easy_install pep8 +" 3. Restart Vim. +" 4. You can now use the ":Pep8" which will examine current python buffer +" and open quickfix buffer with errors if any. +" +" [1] http://www.python.org/dev/peps/pep-0008/ +" [2] http://pypi.python.org/pypi/pep8 +" [3] http://www.vim.org/scripts/script.php?script_id=2441 +" [4] http://pypi.python.org/pypi/setuptools +" +" }}} + +let s:plugin_path = expand(':p:h', 1) + +if exists("b:did_pep8_plugin") + finish " only load once +else + let b:did_pep8_plugin = 1 +endif + +if !exists("g:pep8_exclude") + let g:pep8_exclude = [] +endif + +function! s:DiscoverPython() + if !exists('g:pep8_py_discovered') + if has('python') + let s:python_command = 'python' + elseif has('python3') + let s:python_command = 'python3' + else + echohl WarningMsg|echomsg + \ "PEP8 command cannot be initialized " + \ "no python support compiled in vim."|echohl None + finish + endif + let g:pep8_py_discovered = 1 + endif +endfunction + +if !exists("b:did_pep8_init") + let b:did_pep8_init = 0 + + if !has('python') + echoerr "pep8_fn.vim plugin requires Vim to be compiled with +python" + finish + endif + call s:DiscoverPython() + + python << EOF +import vim +import sys +from StringIO import StringIO + +try: + import pep8 +except ImportError: + raise AssertionError('Error: pep8_fn.vim requires module pep8') + +class VImPep8(object): + + def __init__(self): + self.fname = vim.current.buffer.name + self.bufnr = vim.current.buffer.number + self.output = [] + self.exclude_list = vim.eval("g:pep8_exclude") + + def reporter(self, lnum, col, text, check): + self.output.append([lnum, col, text]) + + def run(self): + pep8.process_options(['-r', vim.current.buffer.name]) + checker = pep8.Checker(vim.current.buffer.name) + checker.report_error = self.reporter + checker.check_all() + self.process_output() + + def process_output(self): + vim.command('call setqflist([])') + qf_list = [] + qf_dict = {} + + for line in self.output: + skip = False + for exclude_pattern in self.exclude_list: + if exclude_pattern in line[2]: + skip = True + break + if skip: + continue + qf_dict['bufnr'] = self.bufnr + qf_dict['lnum'] = line[0] + qf_dict['col'] = line[1] + qf_dict['text'] = line[2] + qf_dict['type'] = line[2][0] + qf_list.append(qf_dict) + qf_dict = {} + + self.output = [] + vim.command('call setqflist(%s)' % str(qf_list)) + if qf_list: + vim.command('copen') +EOF + let b:did_pep8_init = 1 +endif + +if !exists('*s:Pep8') + function s:Pep8() + python << EOF +VImPep8().run() +EOF + endfunction +endif + +if !exists(":Pep8") + command Pep8 call s:Pep8() +endif