diff options
author | Florian Pritz <bluewind@xssn.at> | 2010-03-07 21:12:10 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xssn.at> | 2010-03-07 21:49:17 +0100 |
commit | 86ae02f7aef603ce82e86b0f09758f415472ca04 (patch) | |
tree | 1f3ecc662ad220c33a6cb1a9c73a64102e16eca5 /.vim/ftplugin | |
parent | 31a3053622046dbfd4454cb16af1d538788266ac (diff) | |
download | dotfiles-86ae02f7aef603ce82e86b0f09758f415472ca04.tar.gz dotfiles-86ae02f7aef603ce82e86b0f09758f415472ca04.tar.xz |
vim: new plugin; new syntax file
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to '.vim/ftplugin')
-rw-r--r-- | .vim/ftplugin/python_editing.vim | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/.vim/ftplugin/python_editing.vim b/.vim/ftplugin/python_editing.vim new file mode 100644 index 0000000..531ea70 --- /dev/null +++ b/.vim/ftplugin/python_editing.vim @@ -0,0 +1,85 @@ +" Only do this when not done yet for this buffer +if exists("b:did_ftplugin") +finish +endif +let b:did_ftplugin = 1 + +map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR> +map <buffer> gd /def <C-R><C-W><CR> + +set foldmethod=expr +set foldexpr=PythonFoldExpr(v:lnum) +set foldtext=PythonFoldText() + +map <buffer> f za +map <buffer> F :call ToggleFold()<CR> +let b:folded = 1 + +function! ToggleFold() + if( b:folded == 0 ) + exec "normal! zM" + let b:folded = 1 + else + exec "normal! zR" + let b:folded = 0 + endif +endfunction + +function! PythonFoldText() + + let size = 1 + v:foldend - v:foldstart + if size < 10 + let size = " " . size + endif + if size < 100 + let size = " " . size + endif + if size < 1000 + let size = " " . size + endif + + if match(getline(v:foldstart), '"""') >= 0 + let text = substitute(getline(v:foldstart), '"""', '', 'g' ) . ' ' + elseif match(getline(v:foldstart), "'''") >= 0 + let text = substitute(getline(v:foldstart), "'''", '', 'g' ) . ' ' + else + let text = getline(v:foldstart) + endif + + return size . ' lines:'. text . ' ' + +endfunction + +function! PythonFoldExpr(lnum) + + if indent( nextnonblank(a:lnum) ) == 0 + return 0 + endif + + if getline(a:lnum-1) =~ '^\(class\|def\)\s' + return 1 + endif + + if getline(a:lnum) =~ '^\s*$' + return "=" + endif + + if indent(a:lnum) == 0 + return 0 + endif + + return '=' + +endfunction + +" In case folding breaks down +function! ReFold() + set foldmethod=expr + set foldexpr=0 + set foldnestmax=1 + set foldmethod=expr + set foldexpr=PythonFoldExpr(v:lnum) + set foldtext=PythonFoldText() + echo +endfunction + |