Vasily-X / AutoFoldCode

A Sublime Text package that saves/restores folded code regions in files automatically.
25 stars 5 forks source link

Close event (`on_close`) should not be listened to (or should be documented) #9

Closed 64kramsystem closed 5 years ago

64kramsystem commented 5 years ago

AFC currently listens on two events related to save:

Based on a generic understanding of the code, it's not clear why the close event should be listened to, since the act of closing a document itself is unrelated to the act of saving it. Listening on saves should be a guarantee on itself that the AFC state persistence is in sync with the corresponding document.

There are two main cases where this applies (I'm opening a separate issue for a bug caused by this), one of whom is:

AFC will now perform a save. This is unnnecessary, since no changes have been made to the document.

Since I'm not familiar with the ST3 event system, it's possible that there are cases where the close event should be listened to, however, I think they're not obvious, so in this case, it would make the code more understandable if a documentating comment would be added to the on_close method.

acheronfail commented 5 years ago

AFC will now perform a save. This is unnnecessary, since no changes have been made to the document.

The plugin saves the state on close because Sublime Text has a "hot exit" feature (ie: if you close a project window with unsaved buffers, then the files are not saved but the state is saved in Sublime Text itself).

Listening on close means that folds in this case are preserved, since if it only listened on save then it would fail to remember these code folds.

acheronfail commented 5 years ago

This is fixed by #11