mirror of
https://github.com/gryf/.vim.git
synced 2025-12-17 19:40:29 +01:00
Moving from pathogen to NeoBundle
This commit is contained in:
56
ftplugin/python/common.vim
Normal file
56
ftplugin/python/common.vim
Normal file
@@ -0,0 +1,56 @@
|
||||
setlocal cinkeys-=0#
|
||||
setlocal indentkeys-=0#
|
||||
setlocal foldlevel=100
|
||||
setlocal foldmethod=indent
|
||||
setlocal list
|
||||
setlocal noautoindent
|
||||
setlocal smartindent
|
||||
setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class,with
|
||||
setlocal smarttab
|
||||
|
||||
set wildignore+=*.pyc
|
||||
|
||||
inoremap # X<BS>#
|
||||
|
||||
"set ofu=syntaxcomplete#Complete
|
||||
|
||||
"autocmd FileType python setlocal omnifunc=pysmell#Complete
|
||||
let python_highlight_all=1
|
||||
|
||||
"I don't want to have pyflakes errors in qfix, it interfering with Pep8/Pylint
|
||||
let g:pyflakes_use_quickfix = 0
|
||||
|
||||
"Load views for py files
|
||||
autocmd BufWinLeave *.py mkview
|
||||
autocmd BufWinEnter *.py silent loadview
|
||||
|
||||
finish "end here. all below is just for the record.
|
||||
|
||||
" Pylint function, which can be optionally mapped to some keys. Currently
|
||||
" not used.
|
||||
if !exists('*<SID>runPyLint')
|
||||
function <SID>runPyLint()
|
||||
echohl Statement
|
||||
echo "Running pylint (ctrl-c to cancel) ..."
|
||||
echohl Normal
|
||||
:Pylint
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if !exists('*<SID>PyLintBuf')
|
||||
function <SID>PyLintBuf()
|
||||
echohl Statement
|
||||
echo "Running pylint (ctrl-c to cancel) ..."
|
||||
echohl Normal
|
||||
let file = expand('%:p')
|
||||
let cmd = 'pylint --reports=n --output-format=text "' . file . '"'
|
||||
|
||||
if has('win32') || has('win64')
|
||||
let cmd = 'cmd /c "' . cmd . '"'
|
||||
endif
|
||||
|
||||
exec "bel silent new " . file . ".lint"
|
||||
exec "silent! read! " . cmd
|
||||
endfunction
|
||||
endif
|
||||
|
||||
135
ftplugin/python/pep8_fn.vim
Normal file
135
ftplugin/python/pep8_fn.vim
Normal file
@@ -0,0 +1,135 @@
|
||||
" File: pep8_fn.vim
|
||||
" Author: Roman 'gryf' Dobosz (gryf73 at gmail.com)
|
||||
" Version: 1.0
|
||||
" 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
|
||||
"
|
||||
" }}}
|
||||
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
158
ftplugin/python/pylint_fn.vim
Normal file
158
ftplugin/python/pylint_fn.vim
Normal file
@@ -0,0 +1,158 @@
|
||||
" File: pylint_fn.vim
|
||||
" Author: Roman 'gryf' Dobosz (gryf73 at gmail.com)
|
||||
" Version: 1.0
|
||||
" Last Modified: 2010-09-11
|
||||
"
|
||||
" Description: " {{{
|
||||
"
|
||||
" Overview
|
||||
" --------
|
||||
" This plugin provides ":Pylint" command, which put pylint result into quickfix
|
||||
" buffer. This function does not uses pylint[1] command line utility, only
|
||||
" python pylint.lint module is used instead. So it makes the pylint
|
||||
" egg/package required for running this script.
|
||||
"
|
||||
" 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[2] plugin.
|
||||
"
|
||||
" Installation
|
||||
" ------------
|
||||
" 1. Copy the pylint_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 pylint from python interpreter (it should
|
||||
" report no error):
|
||||
" >>> import pylint
|
||||
" >>>
|
||||
" If there are errors, install pylint first. Simplest way to do it, is to
|
||||
" use easy_install[3] shell command as a root:
|
||||
" # easy_install pylint
|
||||
" 3. Restart Vim.
|
||||
" 4. You can now use the ":Pylint" which will examine current python buffer
|
||||
" and open quickfix buffer with errors if any.
|
||||
"
|
||||
" [1] http://www.logilab.org/project/pylint
|
||||
" [2] http://www.vim.org/scripts/script.php?script_id=2441
|
||||
" [3] http://pypi.python.org/pypi/setuptools
|
||||
" }}}
|
||||
|
||||
if exists("b:did_pylint_plugin")
|
||||
finish " only load once
|
||||
else
|
||||
let b:did_pylint_plugin = 1
|
||||
endif
|
||||
|
||||
if !exists('*s:CheckPylint')
|
||||
function s:CheckPylint()
|
||||
python << EOF
|
||||
try:
|
||||
import vim
|
||||
from pylint import lint
|
||||
from pylint.reporters.text import TextReporter
|
||||
except ImportError:
|
||||
vim.command("return 0")
|
||||
vim.command("return 1")
|
||||
EOF
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if s:CheckPylint() == 0
|
||||
finish
|
||||
endif
|
||||
|
||||
if !exists("b:did_pylint_init")
|
||||
let b:did_pylint_init = 0
|
||||
|
||||
if !has('python')
|
||||
echoerr "Error: pylint_fn.vim requires Vim to be compiled with +python"
|
||||
finish
|
||||
endif
|
||||
|
||||
python << EOF
|
||||
import sys
|
||||
import re
|
||||
from StringIO import StringIO
|
||||
|
||||
class VImPylint(object):
|
||||
|
||||
sys_stderr = sys.stderr
|
||||
dummy_stderr = StringIO()
|
||||
conf_msg = 'No config file found, using default configuration\n'
|
||||
|
||||
@classmethod
|
||||
def run(self):
|
||||
"""execute pylint and fill the quickfix"""
|
||||
|
||||
# clear QF window
|
||||
vim.command('call setqflist([])')
|
||||
|
||||
# args
|
||||
args = ['-rn', # display only the messages instead of full report
|
||||
'-iy', # Include message's id in output
|
||||
vim.current.buffer.name]
|
||||
|
||||
buf = StringIO() # file-like buffer, instead of stdout
|
||||
reporter = TextReporter(buf)
|
||||
|
||||
sys.stderr = self.dummy_stderr
|
||||
lint.Run(args, reporter=reporter, exit=False)
|
||||
sys.stderr = self.sys_stderr
|
||||
|
||||
self.dummy_stderr.seek(0)
|
||||
error_list = self.dummy_stderr.readlines()
|
||||
self.dummy_stderr.truncate(0)
|
||||
if error_list and self.conf_msg in error_list:
|
||||
error_list.remove(self.conf_msg)
|
||||
if error_list:
|
||||
raise Exception(''.join(error_list))
|
||||
|
||||
buf.seek(0)
|
||||
|
||||
bufnr = vim.current.buffer.number
|
||||
code_line = {}
|
||||
error_list = []
|
||||
|
||||
carriage_re = re.compile(r'\s*\^+$')
|
||||
error_re = re.compile(r'^([C,R,W,E,F].+):\s+?([0-9]+):?.*:\s(.*)$')
|
||||
|
||||
for line in buf:
|
||||
line = line.rstrip() # remove trailing newline character
|
||||
|
||||
if error_re.match(line):
|
||||
if code_line:
|
||||
code_line['bufnr'] = bufnr
|
||||
error_list.append(code_line)
|
||||
code_line = {}
|
||||
|
||||
code_line['type'], code_line['lnum'], code_line['text'] = \
|
||||
error_re.match(line).groups()
|
||||
|
||||
if carriage_re.match(line) and code_line:
|
||||
code_line['col'] = carriage_re.match(line).group().find('^') \
|
||||
+ 1
|
||||
vim.command('call setqflist(%s)' % str(error_list))
|
||||
if error_list:
|
||||
vim.command('copen')
|
||||
EOF
|
||||
let b:did_pylint_init = 1
|
||||
endif
|
||||
|
||||
if !exists('*s:Pylint')
|
||||
function s:Pylint()
|
||||
python << EOF
|
||||
VImPylint.run()
|
||||
EOF
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if !exists(":Pylint")
|
||||
command Pylint call s:Pylint()
|
||||
endif
|
||||
Reference in New Issue
Block a user