2

Environment:Ubuntu 11.10 gedit 3.2.3
When I open a specific .php file with gedit, it will appear in a flash and disappear immediately. I searched the web and found one way to get around this - use gconf to change the encoding of gedit but I didn't find the key it mentioned. I tried to use VIM to change the encoding of this .php file to UTF-8 and that didn't work either.

4
  • 1
    Run gedit from a terminal and see if there are any error messages when opening that file.
    – Renan
    Apr 3, 2012 at 17:27
  • @Renan Yes,"GtkSourceView:ERROR:gtksourcecontextengine.c:6012:update_syntax: assertion failed: (g_slist_length (ce->priv->invalid) <= 1) "
    – dotslashlu
    Apr 3, 2012 at 17:28
  • 1
    this is rather strange, I think you have found a bug. There is this bug report in Launchpad which looks similar. but it's marked as "expired".
    – Renan
    Apr 3, 2012 at 17:40
  • Same error here in 2017: gedit ~/Desktop/params.php... output: ** GtkSourceView:ERROR:gtksourcecontextengine.c:5545:update_syntax: assertion failed: (g_slist_length (ce->priv->invalid) <= 1) Aborted (core dumped)
    – ezze
    Nov 25, 2017 at 19:46

2 Answers 2

0

I had a similar problem (caused by a different bug), but the underlying causes might be similar enough for this to work:

gedit saves metadata about all known files using the GnomeVFS. If that metadata contains something gedit doesn't "like", it crashes.

As a workaround, create a copy of the file from the command line (not in Nautilus). cp doesn't preserve the metadata, so this allow you to open the file if the metadata is in fact the problem.

In case it is, you can inspect the file's metadata by executing the following command:

gvfs-info -a metadata FILENAME

Then, one by one, try erasing the entries using the following syntax:

gvfs-set-attribute FILENAME metadata::ATTRIBUTE ''
3

BOM was the culprit in my case. In order to remove it from PHP file run the following:

sed '1s/^\xEF\xBB\xBF//' < ~/Desktop/params.php > ~/Desktop/params2.php

In order to overwrite original file use another command:

sed -i '1s/^\xEF\xBB\xBF//' ~/Desktop/params.php

If BOM is in a source file it will be removed, if not, then file will remain unchanged.

The answer is taken from here.

1
  • Same here. It seems to depend on the file extension as well; it's fine with a UTF-8 BOM in a file named *.txt, but in a *.pl or *.php file it makes it blow up. (I assume this is related to the syntax highlighting somehow.)
    – ruakh
    Apr 6, 2019 at 2:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .