elpy icon indicating copy to clipboard operation
elpy copied to clipboard

elpy-black-fix-code recenters window to put cursor on bottom line

Open livnev opened this issue 3 years ago • 2 comments

Summary

When running elpy-black-fix-code, the window always seems to get recentered to make the cursor on the bottom line. This occurs even if the change effected by black doesn't involve adding or removing lines to the buffer. This is particularly cumbersome if elpy-black-fix-code is added to before-save-hook, since it causes one to lose one's position in the buffer temporarily after every save.

Steps to reproduce

Create a buffer with enough lines to fill the window:

screenshot141

Center the window on some line that is roughly in the middle:

screenshot143

Add some trivial formatting change that will get fixed by elpy-black-fix-code (like inserting a space):

screenshot144

Run elpy-black-fix-code, in addition to the expected reformatting, the window gets recentered to put the cursor at the bottom:

screenshot145

livnev avatar Oct 24 '21 12:10 livnev

I've noticed that it centers the cursor (keeping it on the same line it was on) as if it were using recenter-top-bottom (bound to C-l by default) to center the buffer vertically in the window. I think perhaps it's going to the "bottom" for you because the buffer isn't more than a screenful. That said, I do think the jump is jarring and (I hope) unneeded.

jeremyheiler avatar Dec 12 '21 01:12 jeremyheiler

Can you post elpy-config? We have some tests failing only for specific python versions. wondering if its related to that

gopar avatar Dec 13 '21 21:12 gopar