--- gedit-2.19.92/gedit/gedit-convert.c.utf8 2007-09-11 17:14:50.000000000 +0200 +++ gedit-2.19.92/gedit/gedit-convert.c 2007-09-11 17:17:35.000000000 +0200 @@ -173,12 +173,31 @@ gedit_convert_to_utf8 (const gchar GSList *encodings; GSList *start; gchar *ret = NULL; + gboolean is_7bit_content = TRUE; + const gchar *cur = content; + gsize i; gedit_debug_message (DEBUG_UTILS, "Automatically detect the encoding used"); encodings = gedit_prefs_manager_get_auto_detected_encodings (); + /* If the content is entirely 7-bit data, prepend the current + locale encoding to auto_detect encodings so that it is tested first + (e.g. before UTF-8). */ + + for (i = 0; i < len; i++, cur++) { + if (*cur & 0x80) { + is_7bit_content = FALSE; + break; + } + } + if (is_7bit_content) { + gedit_debug_message (DEBUG_UTILS, + "Content is 7-bit: assuming currrent locale charset (overriding prefs)"); + encodings = g_slist_prepend (encodings, (gpointer)gedit_encoding_get_current ()); + } + if (encodings == NULL) { gedit_debug_message (DEBUG_UTILS, "encodings == NULL"); --- gedit-2.19.92/gedit/gedit-document.c.utf8 2007-09-11 17:17:58.000000000 +0200 +++ gedit-2.19.92/gedit/gedit-document.c 2007-09-11 17:18:29.000000000 +0200 @@ -658,7 +658,7 @@ gedit_document_init (GeditDocument *doc) g_get_current_time (&doc->priv->time_of_last_save_or_load); - doc->priv->encoding = gedit_encoding_get_utf8 (); + doc->priv->encoding = gedit_encoding_get_current (); gtk_source_buffer_set_max_undo_levels (GTK_SOURCE_BUFFER (doc), gedit_prefs_manager_get_undo_actions_limit ());