yapfify icon indicating copy to clipboard operation
yapfify copied to clipboard

yapfify-region also modifies outside the region

Open braineo opened this issue 6 years ago • 2 comments

While expecting yapfify-region modifies selected region, it also removes trailing whitespaces outside the region.

So it actually modified the whole buffer instead of region

braineo avatar Jan 01 '19 14:01 braineo

I see what you mean, but that must be yapf behaviour than :thinking:. No other formatting is applied.

JorisE avatar Jan 06 '19 20:01 JorisE

Check yapf quickly. Seems yapf is using ast to do the formatting so it removes all trailing whitespace even before reformatting.

Maybe one workaround can be

  1. remember indentation of a region
  2. send that region for reformatting
  3. copy back and replace text between start and end

This will increase the parsing speed for sure that we no longer need to parse the whole buffer for reformatting 10 lines of code. (Personally I tried to format 10 lines in a 30,000 line file which froze emacs instantly)

Drawback will be the selected region must not have syntax error

braineo avatar Jan 07 '19 00:01 braineo