Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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/library.py", line 678, in accelerator_activated
    ret = cb(group, obj, keyval, mod)
  File "/usr/lib/gedit/plugins/snippets/windowactivatable.py", line 216, in accelerator_activated
    return controller.accelerator_activate(keyval, mod)
  File "/usr/lib/gedit/plugins/snippets/document.py", line 148, in accelerator_activate
    self.apply_snippet(snippets[0])
  File "/usr/lib/gedit/plugins/snippets/document.py", line 519, in apply_snippet
    env = self.get_environment()
  File "/usr/lib/gedit/plugins/snippets/document.py", line 483, in get_environment
    v = variables[var](buf)
  File "/usr/lib/gedit/plugins/snippets/document.py", 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/document.py", 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/document.py 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
add comment

1 Answer

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/document.py, changing line 22 from

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

to

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 at 15:30
add comment

Your Answer

 
discard

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.