Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an opt-in feature for calling autopep8 at every save.
- Loading branch information
1 parent
b909b38
commit 6fa4dcc
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|