From 37c7794c40f9e682c3fc6696c4f020ef8475551a Mon Sep 17 00:00:00 2001 From: gryf Date: Mon, 19 Mar 2012 21:45:52 +0100 Subject: [PATCH] Added pmx specific stuff --- .vimrc | 4 + .../ft_python/ftplugin/python/pylint_fn.vim | 25 ++- bundle/snipmate/snippets/_.snippets | 4 + bundle/snipmate/snippets/python.snippets | 16 +- bundle_pmx/compiler/autopylint.vim | 12 + bundle_pmx/ftplugin/python/common.vim | 69 ++++++ bundle_pmx/ftplugin/python/pep8.vim | 55 +++++ bundle_pmx/snippets/pmx.snippets | 90 ++++++++ bundle_pmx/snippets/spyce.snippets | 88 ++++++++ pmxrc.vim | 205 ++++++++++++++++++ 10 files changed, 556 insertions(+), 12 deletions(-) create mode 100644 bundle_pmx/compiler/autopylint.vim create mode 100644 bundle_pmx/ftplugin/python/common.vim create mode 100644 bundle_pmx/ftplugin/python/pep8.vim create mode 100644 bundle_pmx/snippets/pmx.snippets create mode 100644 bundle_pmx/snippets/spyce.snippets create mode 100644 pmxrc.vim diff --git a/.vimrc b/.vimrc index f2589a5..ee062c6 100644 --- a/.vimrc +++ b/.vimrc @@ -424,5 +424,9 @@ if $TERM == 'linux' && !has('gui_running') " fallback to basic 8-color colorscheme colorscheme pablo endif + +if has('win32') && $_PMX == '1' + source $VIM/vimfiles/pmxrc.vim +endif "}}} " vim:ts=4:sw=4:wrap:fdm=marker: diff --git a/bundle/ft_python/ftplugin/python/pylint_fn.vim b/bundle/ft_python/ftplugin/python/pylint_fn.vim index 6e045eb..7ebefd1 100644 --- a/bundle/ft_python/ftplugin/python/pylint_fn.vim +++ b/bundle/ft_python/ftplugin/python/pylint_fn.vim @@ -50,6 +50,24 @@ 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 @@ -59,16 +77,9 @@ if !exists("b:did_pylint_init") endif python << EOF -import vim import sys from StringIO import StringIO -try: - from pylint import lint - from pylint.reporters.text import TextReporter -except ImportError: - raise AssertionError('Pylint is required for this plugin') - class VImPylint(object): sys_stderr = sys.stderr diff --git a/bundle/snipmate/snippets/_.snippets b/bundle/snipmate/snippets/_.snippets index 68a5a58..45452c5 100644 --- a/bundle/snipmate/snippets/_.snippets +++ b/bundle/snipmate/snippets/_.snippets @@ -22,3 +22,7 @@ snippet ~ ­ snippet ... … +snippet fn + `expand("%")` +snippet fp + `expand("%:p")` diff --git a/bundle/snipmate/snippets/python.snippets b/bundle/snipmate/snippets/python.snippets index 24bba7d..41ce05e 100644 --- a/bundle/snipmate/snippets/python.snippets +++ b/bundle/snipmate/snippets/python.snippets @@ -5,11 +5,11 @@ snippet imp import ${1:module} # Module Docstring snippet docs - ''' + """ File: ${1:`Filename('$1.py', 'foo.py')`} Author: ${2:`g:snips_author`} Description: ${3} - ''' + """ snippet wh while ${1:condition}: ${2:# code...} @@ -19,7 +19,9 @@ snippet for # New Class snippet cl class ${1:ClassName}(${2:object}): - """${3:docstring for $1}""" + """ + ${3:docstring for $1} + """ def __init__(self, ${4:arg}): ${5:super($1, self).__init__()} self.$4 = $4 @@ -27,7 +29,9 @@ snippet cl # New Function snippet def def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): - """${3:docstring for $1}""" + """ + ${3:docstring for $1} + """ ${4:pass} snippet deff def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): @@ -106,9 +110,11 @@ snippet docmodule """ snippet debug LOG.debug(self.${1:method_name}.__doc__.strip()) +snippet pywin + import pywin.debugger; pywin.debugger.set_trace() snippet edbg import sys - pydevdPath = r"/mnt/data/IDE/eclipse/plugins/org.python.pydev.debug_1.6.5.2011020317/pysrc" + pydevdPath = r"/home/share/data/IDE/eclipse/plugins/org.python.pydev.debug_1.6.5.2011020317/pysrc" if not pydevdPath in sys.path: sys.path.append(pydevdPath) import pydevd diff --git a/bundle_pmx/compiler/autopylint.vim b/bundle_pmx/compiler/autopylint.vim new file mode 100644 index 0000000..7a20ab6 --- /dev/null +++ b/bundle_pmx/compiler/autopylint.vim @@ -0,0 +1,12 @@ +" Vim compiler file for Python +" Compiler: Static code checking tool for Python +" Maintainer: Roman 'gryf' Dobosz +" Last Change: 2010-09-12 +" Version: 1.0 +if exists("current_compiler") + finish +endif + +let current_compiler = "autopylint" +CompilerSet makeprg=$VIM\\bin\\autopylint.py\ -p8\ %:p +CompilerSet efm=%f\|\ %t\|\ %l\|\ %c\|\ %m,%f\|\ %t\|\ %l\|\ %m diff --git a/bundle_pmx/ftplugin/python/common.vim b/bundle_pmx/ftplugin/python/common.vim new file mode 100644 index 0000000..a9ec46d --- /dev/null +++ b/bundle_pmx/ftplugin/python/common.vim @@ -0,0 +1,69 @@ +setlocal cinkeys-=0# +setlocal indentkeys-=0# +setlocal expandtab +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 +setlocal textwidth=78 +setlocal colorcolumn=+1 +" overwrite status line +setlocal statusline=%<%F\ %{TagInStatusLine()}\ %h%m%r%=%(%l,%c%V%)\ %3p%% + +set wildignore+=*.pyc + +inoremap # X# + +"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 + +compiler autopylint + +if !exists('*PyLintBuf') + function PyLintBuf(save_and_close) + echohl Statement + echo "Running pylint (ctrl-c to cancel) ..." + echohl Normal + let filename = expand('%:p') + let cmd = expand('$VIM') . '\bin\autopylint.py -8 "' . filename . '"' + + if has('win32') || has('win64') + let cmd = 'cmd /c ' . cmd + endif + + exec "bel silent new " . filename . ".lint" + exec "silent! read! " . cmd + if a:save_and_close != 0 + exec "w!" + exec "bd" + endif + endfunction + command -bang -nargs=? PyLintBuf call PyLintBuf(0) +endif +map :PyLintBuf + +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('*runPyLint') + function runPyLint() + echohl Statement + echo "Running pylint (ctrl-c to cancel) ..." + echohl Normal + :Pylint + endfunction +endif + diff --git a/bundle_pmx/ftplugin/python/pep8.vim b/bundle_pmx/ftplugin/python/pep8.vim new file mode 100644 index 0000000..2442d57 --- /dev/null +++ b/bundle_pmx/ftplugin/python/pep8.vim @@ -0,0 +1,55 @@ +if exists("b:did_pdpep8_functions") + finish " only load once +else + let b:did_pdpep8_functions = 1 +endif + +if !exists('*s:pdPep8') + function s:pdPep8() + set lazyredraw + " Close any existing cwindows. + cclose + let l:grepformat_save = &grepformat + let l:grepprogram_save = &grepprg + set grepformat&vim + set grepformat&vim + let &grepformat = '%f:%l:%m' + let &grepprg = 'c:\\Python27\\Scripts\\pep8.exe --repeat --ignore=E111' + if &readonly == 0 | update | endif + silent! grep! % + let &grepformat = l:grepformat_save + let &grepprg = l:grepprogram_save + let l:mod_total = 0 + let l:win_count = 1 + " Determine correct window height + windo let l:win_count = l:win_count + 1 + if l:win_count <= 2 | let l:win_count = 4 | endif + windo let l:mod_total = l:mod_total + winheight(0)/l:win_count | + \ execute 'resize +'.l:mod_total + " Open cwindow + execute 'belowright copen '.l:mod_total + nnoremap c :cclose + set nolazyredraw + redraw! + endfunction + command! Pep8 call s:pdPep8() +endif + +if !exists('*s:pdPep8Buf') + function s:pdPep8Buf() + echohl Statement + echo "Running pep8 (ctrl-c to cancel) ..." + echohl Normal + let file = expand('%:p') + "let cmd = 'pylint --reports=n --output-format=text "' . file . '"' + let cmd = 'c:\\Python26\\Scripts\\pep8.exe "' . file . '"' + + if has('win32') || has('win64') + let cmd = 'cmd /c "' . cmd . '"' + endif + + exec "bel silent new " . file . ".lint" + exec "silent! read! " . cmd + endfunction + command! Pep8buf call s:pdPep8Buf() +endif diff --git a/bundle_pmx/snippets/pmx.snippets b/bundle_pmx/snippets/pmx.snippets new file mode 100644 index 0000000..6876f55 --- /dev/null +++ b/bundle_pmx/snippets/pmx.snippets @@ -0,0 +1,90 @@ + +snippet edbg + import sys + pydevdPath = r"c:\eclipse\plugins\org.python.pydev.debug_2.0.0.2011040403\pysrc" + if not pydevdPath in sys.path: + sys.path.append(pydevdPath) + import pydevd + pydevd.settrace() +snippet utimport + import pdunittest.common.pmxunittest as pmxunittest + +snippet classt + class ${1:Foo}Tests(pmxunittest.TestCase): + """ + Tests for class $1 Tests + """ + def setUp(self): + """ + TODO: Setup test + """ + pass + + def tearDown(self): + """ + TODO: Cleanup test + """ + pass + + def test_${2:method}(self): + """ + Test $2 method of class $1 + """ + ${3:pass} +snippet runt + def run(): + """ + runs unit tests in "interactive" mode + """ + suite1 = pmxunittest.TestLoader().loadTestsFromTestCase(${1:ClassTests}) + suite = pmxunittest.TestSuite([suite1]) + ret = pmxunittest.TextTestRunner().run(suite) + return ret + + if __name__ == '__main__': + run() + + # How to run manually: + # + # C:\> cd L:\runtime\pdpyapp + # C:\> L: + # L:\runtime\pdpyapp> startapp pdunittest\${2:`expand("%:t:r")`} + # + # Use parameters: + # -c (--changes) to check db changes after test run + # -c -r (--report) to gather detailed html report additionally + + tested_modules = ['${3:module}'] # modules referenced by the test + automatic_run = ${4:True} # should it be run automatically? + execution_time = 0.000 # estimated time of test ru +snippet deft + def test_${1:fname}(self): + """ + Test for $1 + """ + ${2:pass} +snippet trace + import traceback + print "", 80*"-" + for _line in traceback.format_stack(): + print _line.strip() +snippet pdlog + from PDLOG import PDLOG + PDLOG(${1:31337}, ${2:"msg"}) +snippet head + """ + Project: 8202 / EBR + Description: ${2:description} + Created: ${3:00}.${4:2010}, ${5:author} + + $RCSfile: ebrfoo.py,v $ + $Source: /var/cvs/pmx/pylib/ebrfoo.py,v $ + $Date: 2010/10/06 14:24:13 $ + $Author: foo $ + $Revision: 1.0 $ + + (c) Copyright ${6:2010} Rockwell Automation, + 40-382 Katowice, Poland + """ + vcsid = "$Header: /var/cvs/pmx/pylib/ebrfoo.py,v 1.1 2009/10/06 14:24:13 foo Exp $" + ${7} diff --git a/bundle_pmx/snippets/spyce.snippets b/bundle_pmx/snippets/spyce.snippets new file mode 100644 index 0000000..fc99449 --- /dev/null +++ b/bundle_pmx/snippets/spyce.snippets @@ -0,0 +1,88 @@ +snippet #! + #!/usr/bin/python + +snippet imp + import ${1:module} +# Module Docstring +snippet docs + ''' + File: ${1:`Filename('$1.py', 'foo.py')`} + Author: ${2:`g:snips_author`} + Description: ${3} + ''' +snippet wh + while ${1:condition}: + ${2:# code...} +snippet for + for ${1:needle} in ${2:haystack}: + ${3:# code...} +# New Class +snippet cl + class ${1:ClassName}(${2:object}): + """${3:docstring for $1}""" + def __init__(self, ${4:arg}): + ${5:super($1, self).__init__()} + self.$4 = $4 + ${6} +# New Function +snippet def + def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): + """${3:docstring for $1}""" + ${4:pass} +snippet deff + def ${1:fname}(${2:`indent('.') ? 'self' : ''`}): + ${3} +# New Method +snippet defs + def ${1:mname}(self, ${2:arg}): + ${3:pass} +# New Property +snippet property + def ${1:foo}(): + doc = "${2:The $1 property.}" + def fget(self): + ${3:return self._$1} + def fset(self, value): + ${4:self._$1 = value} +# Lambda +snippet ld + ${1:var} = lambda ${2:vars} : ${3:action} +snippet . + self. +snippet try Try/Except + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} +snippet try Try/Except/Else + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} + else: + ${5:pass} +snippet try Try/Except/Finally + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} + finally: + ${5:pass} +snippet try Try/Except/Else/Finally + try: + ${1:pass} + except ${2:Exception}, ${3:e}: + ${4:raise $3} + else: + ${5:pass} + finally: + ${6:pass} +# if __name__ == '__main__': +snippet ifmain + if __name__ == '__main__': + ${1:main()} +# __magic__ +snippet _ + __${1:init}__${2} +snippet dbg + import pywin.debugger; pywin.debugger.set_trace() diff --git a/pmxrc.vim b/pmxrc.vim new file mode 100644 index 0000000..b4bd725 --- /dev/null +++ b/pmxrc.vim @@ -0,0 +1,205 @@ +set fileencoding=utf-8 +set runtimepath+=$VIM/vimfiles/bundle_pmx +set viewoptions=cursor +"set guifont=Consolas:h10:cEASTEUROPE +set guifont=DejaVu_Sans_Mono:h9:cEASTEUROPE +set shiftwidth=2 +set softtabstop=2 +set tabstop=2 +set listchars=tab:>-,trail:. +set guioptions=ceg +set mouse=a +set enc=utf-8 +set printoptions=number:y +set pfn=Consolas:h10:cEASTEUROPE + +let Tlist_Ctags_Cmd = expand('$VIM/bin/ctags.exe') +let g:tagbar_ctags_bin = expand('$VIM/bin/ctags.exe') +let g:browser = '"c:\Program Files\Mozilla Firefox\firefox.exe"' + +autocmd BufWritePre *.spy :StripTrailingWhitespaces +autocmd BufWritePre *.spi :StripTrailingWhitespaces +autocmd BufWritePre *.opl :StripTrailingWhitespaces +autocmd BufRead *.opl set filetype=pd_opl + +"CTRL-P +" Don't rely on VCS system, just do stuff relative to current dir. PMX sources +" are too huge +let g:ctrlp_working_path_mode = 0 + +"Grep +" Note: xargs from GnuWin32 package are unusable with this plugin - it refuses +" to pass find output to the grep. Fortunately, cygwin version (which is +" newer in fact) is working just fine. The only thing that is needed to +" set is to quote arguments passed to find: +let Grep_Shell_Quote_Char='"' +" If for some reason it is needed to use tools from GnuWin32 project, comment +" out following line: +let Grep_Cygwin_Find=1 +" and uncomment one below: +"let Grep_Find_Use_Xargs=0 +" Note: without xargs processing of the output will be much more slower than +" with it. + +if has("gui_running") + highlight SpellBad term=underline gui=undercurl guisp=Orange +endif + +"maximize window +au GUIEnter * simalt ~x + +function GuiTabLabel() + " add the tab number + let label = '' "'['.tabpagenr() + + " count number of open windows in the tab + "let wincount = tabpagewinnr(v:lnum, '$') + "if wincount > 1 + " let label .= ', '.wincount + "endif + "let label .= '] ' + + let buflist = tabpagebuflist(v:lnum) + + " add the file name without path information + let n = bufname(buflist[tabpagewinnr(v:lnum) - 1]) + let label .= fnamemodify(n, ':t') + + " modified since the last save? + for bufnr in buflist + if getbufvar(bufnr, '&modified') + let label .= ' *' + break + endif + endfor + + return label +endfunction +set guitablabel=%{GuiTabLabel()} + +"PMX: {{{ +if exists("g:vim_bin_path") + finish +endif +let g:vim_bin_path = expand($VIM) . '/bin' + +let $REF_DRIVE='R:' +let $LOCAL_DRIVE='L:' +let $PMXOS='WINNT' +let $PDMODE='RELEASE' +let $SOLUTION='mes' +let $OUIDICTPATH='../genR.WIN' +let $PATH='c:\Python23;' . $PATH +let $USE_HG_REPO='Y' + +if !exists("g:pmx_path") + let g:pmx_path = "L:" +endif + +if !has("python") + finish +endif + +" Switch between HG and CVS in vcscommand plugin +function VCSSwitch() + echohl Statement + if exists("g:VCSTypeOverride") + if g:VCSTypeOverride == "HG" + let g:VCSTypeOverride = "CVS" + echo "Switched to CVS" + else + let g:VCSTypeOverride = "HG" + echo "Switched to HG" + endif + else + let g:VCSTypeOverride = "HG" + echo "Switched to HG" + endif + echohl Normal +endfunction +map :call VCSSwitch() + + +" stupid hard-coded way to add paths to let VIm know where to look for the +" files, yet it is not perfect. +python << EOF +import os +import vim + +pmx_path = vim.eval("g:pmx_path") +pmx_path = pmx_path.replace("\\", "/") + +if not pmx_path.endswith("/"): + pmx_path += "/" + +vim.command("set tags+=" + pmx_path + ".vim_cache/tags") + +pyothers = ["runtime/System/BIN.Win/others/python/Lib/PIL", + "runtime/System/BIN.Win/others/python/Lib/coverage", + "runtime/System/BIN.Win/others/python/Lib/ctypes", + "runtime/System/BIN.Win/others/python/Lib/pyPdf"] + +pyfiles = ["runtime/System/pylib", + "runtime/System/pylib/PythonWin", + "runtime/System/pylib/pdgui", + "runtime/System/pylib/pdoracle", + "runtime/System/pylib/pdpersis", + "runtime/System/pylib/pdunittest", + "runtime/System/pylib/pdtest", + "runtime/System/pylib/pdutil", + "runtime/System/pylib/spyce", + "runtime/System/pylib/std", + "runtime/System/pylib/std/lib-old", + "runtime/System/pylib/std/lib-tk", + "runtime/System/pylib/win32/lib"] + +for i in pyfiles: + vim.command("set path+=" + pmx_path + i) + +for i in pyothers: + vim.command("set path+=" + pmx_path + i) + +def map_drive_L(path): + assert os.path.exists(path) + path = os.path.abspath(path) + if os.path.exists("L:"): + os.system("subst L: /D") + os.system("subst L: " + path) + +def update_tags(): + assert os.path.exists(pmx_path) + + opl_cfg = os.path.normpath(os.path.join(vim.eval("$VIM"), + "bin", + "ctags_opl.cnf")) + opl_path = os.path.normpath(os.path.join(pmx_path, "opl")) + pylib_path = os.path.join(pmx_path, "runtime", "system", "pylib") + pylib_path = os.path.normpath(pylib_path) + pylib_path += " " + os.path.normpath(pmx_path + \ + 'runtime/System/BIN.Win/others/python/Lib') + + tag_dir = os.path.join(pmx_path, ".vim_cache") + tag_path = os.path.normpath(os.path.join(tag_dir, "tags")) + + if not os.path.exists(tag_dir): + os.mkdir(tag_dir) + + # find tags for python files and tags for OPL files if exists + ctags = os.path.join(vim.eval("$VIM"), "bin", "ctags.exe") + ctags = os.path.normpath(ctags) + cmd = 'start cmd /c ' + cmd += ctags + ' -R --python-kinds=-i' + if os.path.exists(opl_path) and os.path.exists(opl_cfg): + cmd += ' --options=' + opl_cfg + cmd += ' -f ' + tag_path + ' ' + pylib_path + if os.path.exists(opl_path) and os.path.exists(opl_cfg): + cmd += ' ' + opl_path + print cmd + os.system(cmd) +EOF + +command -nargs=1 -complete=dir MapDriveL py map_drive_L() +command UpdateTags py update_tags() +"}}} + +" vim:ts=4:sw=4:wrap:fdm=marker: