Skip to content

Improve performance of white space removal#137

Merged
klen merged 2 commits into
python-mode:masterfrom
djsmith42:master
Oct 22, 2012
Merged

Improve performance of white space removal#137
klen merged 2 commits into
python-mode:masterfrom
djsmith42:master

Conversation

@djsmith42

Copy link
Copy Markdown

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.

Dave Smith added 2 commits October 13, 2012 20:56
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.
klen added a commit that referenced this pull request Oct 22, 2012
Improve performance of white space removal
@klen klen merged commit d6b3a73 into python-mode:master Oct 22, 2012
@klen

klen commented Oct 22, 2012

Copy link
Copy Markdown
Collaborator

Awesome. Thanks

@djsmith42

Copy link
Copy Markdown
Author

Klen, for some reason, my patch doesn't work all the time. Occasionally, it leaves white space, and I haven't figured out the cause yet. Does it work for you?

@djsmith42

Copy link
Copy Markdown
Author

Found the cause: The problem appears to manifest when I have multiple split buffers. I'll look into it today.

@djsmith42

Copy link
Copy Markdown
Author

This patch fixes it, but it won't work for python files without a ".py" extension. I tried using autocmd FileType python autocmd BufWritePre ..., but that didn't work either.

diff --git a/ftplugin/python/pymode.vim b/ftplugin/python/pymode.vim
index ac77f1e..27e847c 100644
--- a/ftplugin/python/pymode.vim
+++ b/ftplugin/python/pymode.vim
@@ -138,7 +138,7 @@ if pymode#Option('utils_whitespaces')
         :silent! %s/\s\+$//
         call setpos('.', cursor_pos)
     endfunction
-    au BufWritePre <buffer> call PyModeTrimEndWhiteSpace()
+    autocmd BufWritePre *.py :call PyModeTrimEndWhiteSpace()
 endif

@djsmith42

Copy link
Copy Markdown
Author

Ah hah. I see you fixed it in 9db9857. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants