emacs-format-all-the-code icon indicating copy to clipboard operation
emacs-format-all-the-code copied to clipboard

How can we implement a `format-modified-region` with `format-all-region`

Open xeechou opened this issue 1 year ago • 3 comments

Hi, it is nice to have format-all-region that only format one region of the buffer. However I am not sure how useful it is. I tried to archive formatting only the modified regions (as it is already available feature in vscode, neovim, etc) for large code base with legacy code.

I try to implement this feature with (after-change-functions) hook and format-all-region but it is not possible since format-all-region modifies the entire buffer anyway.

I am wondering how we can archive the similar feature as in https://github.com/microsoft/vscode/pull/104994 ?

xeechou avatar Oct 15 '23 19:10 xeechou

it is not possible since format-all-region modifies the entire buffer anyway.

It should not modify the entire buffer. That sounds like a bug. Which formatter did you test it with?

lassik avatar Oct 18 '23 16:10 lassik

it is not possible since format-all-region modifies the entire buffer anyway.

It should not modify the entire buffer. That sounds like a bug. Which formatter did you test it with?

I don't meant it changed actual "content" of the entire buffer. If you turned on highlight-changes-mode and run a format-all-région you will see. I am using clang-format

xeechou avatar Oct 19 '23 15:10 xeechou

I found the only reliable way to format only changed lines is relying on output from diff. I created a small fmo-mode to apply format-all-region on only changed lines.

xeechou avatar Oct 27 '23 19:10 xeechou