After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741545 - get_language() in "loaded" signal handler returns NULL
get_language() in "loaded" signal handler returns NULL
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
3.14.x
Other Linux
: Normal normal
: ---
Assigned To: Gedit maintainers
Gedit maintainers
Depends on:
Blocks:
 
 
Reported: 2014-12-15 08:05 UTC by fhuemer
Modified: 2014-12-15 11:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
simple plugin demonstrating the bug (10.00 KB, application/x-tar)
2014-12-15 08:05 UTC, fhuemer
Details

Description fhuemer 2014-12-15 08:05:35 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]
Comment 1 Sébastien Wilmet 2014-12-15 11:02:42 UTC
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).
Comment 2 fhuemer 2014-12-15 11:18:24 UTC
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.
Comment 3 Sébastien Wilmet 2014-12-15 11:38:47 UTC
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).