Anonymous avatar Anonymous committed 304e3ee

Do not hardcode '&encoding' to "utf-8", ask vim instead.

Comments (0)

Files changed (1)

         result = self._position_to_offset(*self.cursor)
         return result
 
+    def _get_encoding(self):
+        return vim.eval('&encoding')
+    def _encode_line(self, line):
+        return line.encode(self._get_encoding())
+    def _decode_line(self, line):
+        return line.decode(self._get_encoding())
+
     def _position_to_offset(self, lineno, colno):
         result = min(colno, len(self.buffer[lineno -1]) + 1)
         for line in self.buffer[:lineno-1]:
-            line = line.decode('utf-8')
+            line = self._decode_line(line)
             result += len(line) + 1
         return result
 
     def get_text(self):
-        return u'\n'.join(self.buffer).decode('utf-8') + u'\n'
+        return self._decode_line('\n'.join(self.buffer)) + u'\n'
 
     def get_region(self):
         start = self._position_to_offset(*self.buffer.mark('<'))
 
     def _get_cursor(self):
         lineno, col = vim.current.window.cursor
-        line = vim.current.line[:col].decode('utf-8')
+        line = self._decode_line(vim.current.line[:col])
         col = len(line)
         return (lineno, col)
 
     def _set_cursor(self, cursor):
         lineno, col = cursor
-        line = vim.current.line.decode('utf-8')
-        line = line[:col].encode('utf-8')
+        line = self._decode_line(vim.current.line)
+        line = self._encode_line(line[:col])
         col = len(line)
         vim.current.window.cursor = (lineno, col)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.