Skip to content

Commit fefcb78

Browse files
author
Dave Smith
committed
Improve performance of white space removal
On large'ish python files, this was taking 10+ seconds at save time. Now it runs instantly, even on very large python files. Cursor position does not move.
1 parent e877c7e commit fefcb78

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ftplugin/python/pymode.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ endif
133133
" Utils {{{
134134

135135
if pymode#Option('utils_whitespaces')
136-
au BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
136+
function PyModeTrimEndWhiteSpace()
137+
let cursor_pos = getpos('.')
138+
%s/\s\+$//
139+
call setpos('.', cursor_pos)
140+
endfunction
141+
au BufWritePre <buffer> call PyModeTrimEndWhiteSpace()
137142
endif
138143

139144
" }}}

0 commit comments

Comments
 (0)