I am the maintainer of Atom-Beautify. Most of the users have “Beautify On Save” enabled. The problem is I do not know how to prevent Atom from saving immediately (synchronously) and wait for the beautification to complete. Atom-Beautify handles beautification asynchronously, so by the time the beautification has completed the TextEditor – which was originally saved – may actually be closed!
This is the current way “Beautify On Save” is handled: https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L507-L556
- On Save event occurs (editor.onDidSave): https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L552-L554
- Perform beautification on text: https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L511-L535
- Check if Editor is still alive: https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L538
- Store reference to editor’s file path: https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L544
- Save with new beautified text: https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L545
- Remove reference to editor’s file path: https://github.com/Glavin001/atom-beautify/blob/c8a8f7b3cbf1f4bdeee249586b8531c0179ee680/src/beautify.coffee#L546
In the end, the TextEditor has been saved twice: the first time with the original text, and the second time later with the beautified code. Ideally, saving to file system actually occurs only only once and Atom waits on Atom-Beautify to complete. Also ensuring the user does not close the editor thus causing editor.save()
to fail.
Any ideas? Thank you in advance!