SublimeText / sublime_lib

Utility library for frequently used functionality in Sublime Text and convenience functions or classes
https://sublimetext.github.io/sublime_lib
MIT License
52 stars 4 forks source link

Add SettingsListener. #166

Open Thom1729 opened 3 years ago

Thom1729 commented 3 years ago

For #164.

Notes:

Thom1729 commented 3 years ago

I've run into a bit of trouble with GlobalSettingsListener. It turns out that EventListeners are never garbage-collected. (I'm pretty sure this is a bug.)

I have solved the problem with a moderately ugly hack. GlobalSettingsListener implements an on_new handler that does nothing. Then, in _on_settings_change, it checks whether that callback is registered. If not, it calls its own __del__.

After spending several hours debugging this, I'm confident that this was the problem and that the solution works — though I wouldn't call it pretty.

(There's no such problem with ViewEventListeners.)

Thom1729 commented 3 years ago

@FichteFoll Any thoughts on the above hack?

FichteFoll commented 3 years ago

Regarding the on_new hack: I think it's reasonable, although I surely wish it wasn't necessary. Yet, I cannot think of a better idea, so LGTM in general.

Thom1729 commented 3 years ago

I wrote up some docs for the projection function. I'm not completely satisfied with it, but it might be good enough.