]> git.phdru.name Git - dotfiles.git/blob - .vim/ftplugin/python.vim
.vim: Use `programming_lang.vim` in `python.vim`
[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 runtime! ftplugin/programming_lang.vim
21 setlocal keywordprg=pydoc
22 compiler python
23
24 if has("unix")
25    autocmd BufWritePost <buffer> call SavePython()
26 endif
27
28 " Compile and remove *.cgi[co] files after compilation; do not remove *.py[co] files;
29 " if it is a shebang script change file mode to make it executable.
30 function! SavePython()
31    let ext = expand("%:e")
32    if ext == "pyem"
33       return
34    elseif ext == "ptl"
35       !compyle-ptl %
36    else
37       !compyle %
38       if ext != "py"
39          !rm -f %[co]
40       endif
41       if getline(1) =~ "^#!"
42          call SetExecutableBit(1)
43       endif
44    endif
45 endfunction
46
47 " Avoid double indent. See https://stackoverflow.com/a/62348570/7976758
48 let g:pyindent_open_paren=shiftwidth()