File: python_autopep8.vim

package info (click to toggle)
vim-autopep8 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 152 kB
  • sloc: makefile: 151; python: 29
file content (28 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

" This function saves the current window state, and executes Autopep8() with
" the user's existing options. After Autopep8 call, the initial window
" settings are restored. Undo recording is also paused during Autopep8 call
function! s:autopep8_on_save()
  if get(g:, "autopep8_on_save", 0)

    " Save cursor position and many other things.
    let l:curw = winsaveview()

    " stop undo recording
    try | silent undojoin | catch | endtry

    call Autopep8()

    " Restore our cursor/windows positions.
    call winrestview(l:curw)

  endif
endfunction

" During every save, also reformat the file with respect to the existing
" autopep8 settings.
augroup vim-python-autopep8
   autocmd!
   autocmd BufWritePre *.py call s:autopep8_on_save()
augroup END