Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply patch instead of replacing whole buffer #15

Open
bdarnell opened this issue Oct 28, 2018 · 5 comments
Open

Apply patch instead of replacing whole buffer #15

bdarnell opened this issue Oct 28, 2018 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@bdarnell
Copy link

Replacing the entire buffer with copy-to-buffer is disruptive: It's a delete followed by a replace, and many links within emacs (including compilation, grep, and occur buffers) will overreact to the deletion by redirecting all links to the beginning of the file. (Reinserting the whole file also causes it to be reparsed for syntax highlighting, which can be kind of slow)

The support for gofmt in go-mode shows a better way, although it's unfortunately a nontrivial amount of code. go-mode asks for a diff instead of rewriting the whole file, then parses the diff and translates it into editing commands. It would be nice if blacken did the same (It would be even nicer if there were one meta-fmt mode for emacs so that this wheel doesn't have to be reinvented for every formatting tool).

@proofit404
Copy link
Contributor

Hi,

I agree to every point in this issue.

I have very limited time, so I spend it on @dry-python project mostly.

If anyone can work on this and submit a PR, I will be more than happy to merge it.

Regards, Artem.

@pmiddend
Copy link
Contributor

@bdarnell After a very short discussion on /r/emacs, I've created #19, which is a more sensitive way to replace buffer contents.

@jidicula
Copy link

jidicula commented Oct 7, 2020

#19 was reverted, are there any plans to try to re-implement the functionality?

@dakra
Copy link
Member

dakra commented Oct 7, 2020

Personally I use https://github.com/raxod502/apheleia which uses a patch and tries very hard that your cursor doesn't move when reformatting. Maybe that's a good alternative.

@jidicula
Copy link

jidicula commented Oct 7, 2020

I'm trying out https://github.com/wbolster/emacs-python-black, but I haven't used it enough to observe how/if the cursor moves when reformatting.

I'll give apheleia a try, though, thanks @dakra!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants