radian-software / apheleia

🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
MIT License
523 stars 74 forks source link

Generalizing this package #210

Open walseb opened 10 months ago

walseb commented 10 months ago

Hello!

I'm working on overhauling a package that uses a git repo to store every change you make in all buffers, so that you can restore your buffer to any previous state at any time (link: https://github.com/walseb/git-backup-ivy).

One major issue I'm facing is that whenever you revert to a previous state, the entire buffer gets overwritten and so all markers get messed up - the same issue this package solves for formatters.

Is there any way I could use this package to solve that problem?

I'd need a function that takes a string and changes the current buffer into that string, maintaining the markers as best it can. After reading the description of this package, it seems that it does exactly that, as well as running the actual formatter processes.

Thank you!

raxod502 commented 10 months ago

You can probably use Apheleia for that. This would be, to my knowledge, the first usage of Apheleia as a library rather than a user-facing application. Bind apheleia-formatters to define an Elisp function formatter and then invoke apheleia-format-buffer. The Elisp function formatter can overwrite the buffer contents with your desired string. If that works, you can provide feedback on the usability from a library perspective and we can consider improvements to the interface.

walseb commented 10 months ago

Great, I will try it out. Thank you!