]> git.phdru.name Git - dotfiles.git/blob - .vim/ftplugin/python.vim
Initial import
[dotfiles.git] / .vim / ftplugin / python.vim
1 if exists("b:did_ftplugin")
2    finish
3 endif
4
5 " Do not set b:did_ftplugin - it prevents standard plugins from running
6 " let b:did_ftplugin = 1 " it will be set in the standard plugin
7
8 if has("iconv") && !exists('b:encoding_set')
9    " Try to recognize the file encoding and convert the file
10    let line = getline(1)
11    if line !~ '^ *#.*coding[=:]\s*\([-0-9A-Za-z_.]\+\)'
12       let line = getline(2)
13    endif
14    if line =~ '^ *#.*coding[=:]\s*\([-0-9A-Za-z_.]\+\)'
15       let encoding = matchlist(line, 'coding[=:]\s*\([-0-9A-Za-z_.]\+\)')[1]
16       call SetupEncoding(encoding)
17    endif
18 endif
19
20 setlocal fo-=t fo+=croql
21 setlocal keywordprg=pydoc
22 setlocal shiftwidth=4 softtabstop=4
23 compiler python
24
25 if has("unix")
26    execute "autocmd BufWritePost " . expand("%") . " call SavePython()"
27 endif
28
29 " Compile and remove *.cgi[co] files after compilation; do not remove *.py[co] files;
30 " if it is a shebang script change file mode to make it executable.
31 function! SavePython()
32    let ext = expand("%:e")
33    if ext == "pyem"
34       return
35    elif ext == "ptl"
36       !compyle-ptl %
37    else
38       !compyle %
39       if ext != "py"
40          !rm -f %[co]
41       endif
42       if getline(1) =~ "^#!"
43          !chmod +x %
44       endif
45    endif
46 endfunction