Skip to content

Commit

Permalink
Add an opt-in feature for calling autopep8 at every save.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahakanbaba committed May 29, 2018
1 parent b909b38 commit 6fa4dcc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions plugin/python_autopep8.vim
@@ -0,0 +1,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

0 comments on commit 6fa4dcc

Please sign in to comment.