lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
604 stars 105 forks source link

Conflict with vimish-fold #98

Open asif-mahmud opened 3 years ago

asif-mahmud commented 3 years ago

Hi, i have been using vimish-fold package to persist my code folding at session restores. But unfortunately, when i try to run - format-all-buffer when there are 1 or more folds active, it gives me a minibuffer message - Text is read-only, but it isn't ! I can save the buffer with C-x C-s as usual. If you could check this situation, it would be very helpful. Thanks in advance.

lassik commented 3 years ago

Thanks for the bug report. I have no experience with any of the folding packages in Emacs. Format-all doesn't try to make anything read-only at any point. Perhaps vimish-fold makes the hidden text read-only so that's probably what causes the problem. Format-all tries to rewrite the whole buffer; if you have a fold active, part of that rewrite hits the folded area.

lassik commented 3 years ago

I attempted a fix in the read-only-bugfix branch. Can you try loading that version of format-all and check whether it solves the problem?

asif-mahmud commented 3 years ago

Let me check. Will let you know soon.

asif-mahmud commented 3 years ago

Just checked, it does work now. But it also removes the folds. I am very new to elisp, learning for just a few days. Don't know how much work it will be to keep the read-only parts intact. But any effort is much appreciated. I checked another package py-yapf which does formatting for python scripts with yapf. It does keep the folds intact and formats as well, but it sometimes leaves a lot of temporary files undeleted. I guess, the author's idea was to create a new file, format it, save it (optionally) and insert the saved data, but it somehow managed to keep the folds. But i am too noob at elisp right now to figure out how thats happening. But your package is way more feature full and looks like the right way to do formatting. Anyway, thanks again for the quick fix. I hope you can figure out a way to keep the read-only properties intact.

lassik commented 3 years ago

Just checked, it does work now.

Good to know. I'll push the bugfix into MELPA since it solves part of the problem and doesn't make things any worse.

But it also removes the folds. I am very new to elisp, learning for just a few days. Don't know how much work it will be to keep the read-only parts intact. But any effort is much appreciated. I checked another package py-yapf which does formatting for python scripts with yapf. It does keep the folds intact and formats as well, but it sometimes leaves a lot of temporary files undeleted. I guess, the author's idea was to create a new file, format it, save it (optionally) and insert the saved data, but it somehow managed to keep the folds. But i am too noob at elisp right now to figure out how thats happening. But your package is way more feature full and looks like the right way to do formatting. Anyway, thanks again for the quick fix. I hope you can figure out a way to keep the read-only properties intact.

Thanks for doing the legwork. I suspect that py-yapf finds the difference between the old and new code and modifies only the changed parts of the buffer. Format-all currently takes the easy way out, erasing the buffer and rewriting it completely from scratch. This is not ideal, and if someone can do a pull request to make format-all compute a diff and touch only the changed portions, I'll happily accept it.

Can you ask py-yapf's author what they are doing to make the folds work? My time to work on format-all is very limited. (I've been trying to find new maintainer(s) for it but none have volunteered so far, so development is slow.)

asif-mahmud commented 3 years ago

I understand. I will try to find out how py-yapf handles it.

larrasket commented 10 months ago

Any update on this?