[meld/meld-3-14] filediff: Use locale-based default encodings (bgo#752307, bgo#753427)



commit 0f51f387226f5bca8b7bf496eacd07f4af5d601e
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Aug 12 11:12:56 2015 +1000

    filediff: Use locale-based default encodings (bgo#752307, bgo#753427)
    
    Taking some inspiration from GtkSourceViewLoader, this patch changes
    our list of encodings-to-try when loading files to follow a set
    pattern.
    
    While this is a behaviour change, it's basically just adding the
    locale-specific charset and UTF-16 to the list to be loaded; it's
    unlikely that the latin-1 -> iso-8859-15 is going to do anything but
    load more files correctly.
    
    The default list of encodings in our schema is left as ["utf8"], so
    that if users add things to this list, there is at least a reasonable
    hint that they should add then *after* UTF-8 to preserve sane loading.

 meld/filediff.py |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 787c989..9ff8e81 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -16,6 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import codecs
 import copy
 import functools
 import io
@@ -1107,8 +1108,14 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self._disconnect_buffer_handlers()
         self.linediffer.clear()
         self.queue_draw()
-        try_codecs = list(settings.get_value('detect-encodings'))
-        try_codecs.append('latin1')
+
+        # Build and uniquify a list of encodings to try out
+        extras = list(settings.get_value('detect-encodings'))
+        builtin = ['utf-8', GLib.get_codeset(), 'utf-16le', 'iso8859-15']
+        allencs = [codecs.lookup(c).name for c in extras + builtin]
+        seen = set()
+        try_codecs = [c for c in allencs if c not in seen and not seen.add(c)]
+
         yield _("[%s] Opening files") % self.label_text
         tasks = []
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]