GNOME Bugzilla – Bug 741545
get_language() in "loaded" signal handler returns NULL
Last modified: 2014-12-15 11:38:47 UTC
Created attachment 292739 [details] simple plugin demonstrating the bug When gedit is started and a (python) plugin that trys to get the GtkSourceLanguage object associated with a document the get_language() function returns None. When the document is saved the GtkSourceLanguage object is created apparently, because the get_language() function no longer retruns None. The problem is also fixed if the plugin is manually deactivated and activated again. In version 3.10.4 everything worked fine, but with version 3.14.2 the discribed bug appears. I've prepeared a simple plugin to demonstate the bug. Install the plugin and run gedit bugtest.py The output is [bugtest.py] doc.get_language() == None [Error] while it should be (like in version 3.10) [bugtest.py] doc.get_language() != None [OK]
I think it's the same problem as: https://git.gnome.org/browse/gedit-plugins/commit/?id=b279c0f7d8df4abb716cd0ef2ccac8ba3cee0b6a The solution for the synctex plugin was to run get_language() (indirectly) in an idle. A better solution is to connect to the "loaded" signal with the AFTER flag, because the GtkSourceLanguage is set in the GeditDocument object handler (see gedit_document_loaded_real()). But to avoid breaking plugins, I think the best is to change the "loaded" and "saved" signals to be G_SIGNAL_RUN_FIRST, so the GeditDocument object handlers are first called, and then the other connected handlers (with or without the AFTER flag).
Thanks for the hint. I wasn't aware of the problem with the synctex plugin. I noticed it when I tryed to port my plugin to 3.14.
Fixed: https://git.gnome.org/browse/gedit/commit/?id=a37936ed5abc42d3e6199380202a6eef009cb57b (also backported to the gnome-3-14 branch, it'll be available for the next 3.14.x version) It should now work fine, if you connect to the "loaded" signal (with or without the after flag).