Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just ran into a problem with the snippets plugin of gedit 3.4.1 running on Ubuntu 12.04. The problem is that the snippets plugin stops working (i. e., doesn't react to keyboard shortcuts and tab-completion) when a file has an encoding other than UTF-8, e. g. ISO-8859-1. In that case, the snippets plugin doesn't work any more and the error output on the console states:

Traceback (most recent call last):
  File "/usr/lib/gedit/plugins/snippets/", line 678, in accelerator_activated
    ret = cb(group, obj, keyval, mod)
  File "/usr/lib/gedit/plugins/snippets/", line 216, in accelerator_activated
    return controller.accelerator_activate(keyval, mod)
  File "/usr/lib/gedit/plugins/snippets/", line 148, in accelerator_activate
  File "/usr/lib/gedit/plugins/snippets/", line 519, in apply_snippet
    env = self.get_environment()
  File "/usr/lib/gedit/plugins/snippets/", line 483, in get_environment
    v = variables[var](buf)
  File "/usr/lib/gedit/plugins/snippets/", line 348, in env_get_current_line
    return {'utf8': u8, 'noenc': self.string_in_native_doc_encoding(buf, u8)}
  File "/usr/lib/gedit/plugins/snippets/", line 320, in string_in_native_doc_encoding
    except GLib.GError:
NameError: global name 'GLib' is not defined

Apparently, there is a problem in file /usr/lib/gedit/plugins/snippets/ where a function GLib.convert is called whenever the document encoding is not UTF-8. Consequently, if I save the same file as UTF-8, it all works well.

I'm not much into Python, so any pointer how to fix this would be much appreciated.

share|improve this question
up vote 1 down vote accepted

Apparently, this bug is about to be fixed in one of the next versions of Ubuntu. For an immediate fix, simply edit /usr/lib/gedit/plugins/snippets/, changing line 22 from

from gi.repository import Gtk, Gdk, Gio, GtkSource, Gedit


from gi.repository import Gtk, Gdk, Gio, GLib, GtkSource, Gedit

(i. e., include the GLib import). Don't forget to relaunch gedit :-)

share|improve this answer
works great! thank you :-) – vcampitelli Feb 17 '14 at 15:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.