diff --git a/powerline/__init__.py b/powerline/__init__.py index 428e3d46..1bc6fa06 100644 --- a/powerline/__init__.py +++ b/powerline/__init__.py @@ -225,7 +225,7 @@ def create_logger(common_config): return logger -def finish_common_config(common_config): +def finish_common_config(encoding, common_config): '''Add default values to common config and expand ~ in paths :param dict common_config: @@ -235,7 +235,7 @@ def finish_common_config(common_config): Copy of common configuration with all configuration keys and expanded paths. ''' - encoding = getpreferredencoding().lower() + encoding = encoding.lower() if encoding.startswith('utf') or encoding.startswith('ucs'): default_top_theme = 'powerline' else: @@ -407,6 +407,12 @@ class Powerline(object): self.setup_kwargs = {} self.imported_modules = set() + get_encoding = staticmethod(getpreferredencoding) + '''Get encoding used by the current application + + Usually returns encoding of the current locale. + ''' + def create_renderer(self, load_main=False, load_colors=False, load_colorscheme=False, load_theme=False): '''(Re)create renderer object. Can be used after Powerline object was successfully initialized. If any of the below parameters except @@ -431,7 +437,7 @@ class Powerline(object): if load_main: self._purge_configs('main') config = self.load_main_config() - self.common_config = finish_common_config(config['common']) + self.common_config = finish_common_config(self.get_encoding(), config['common']) if self.common_config != self.prev_common_config: common_config_differs = True diff --git a/powerline/bindings/config.py b/powerline/bindings/config.py index d5ec8400..042a6e9c 100644 --- a/powerline/bindings/config.py +++ b/powerline/bindings/config.py @@ -6,6 +6,8 @@ import os import re import sys +from locale import getpreferredencoding + from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY from powerline.lib.config import ConfigLoader from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config @@ -83,7 +85,7 @@ def get_main_config(args): def create_powerline_logger(args): config = get_main_config(args) - common_config = finish_common_config(config['common']) + common_config = finish_common_config(getpreferredencoding(), config['common']) logger = create_logger(common_config) return PowerlineLogger(use_daemon_threads=True, logger=logger, ext='config') diff --git a/powerline/vim.py b/powerline/vim.py index ecea537b..56159f00 100644 --- a/powerline/vim.py +++ b/powerline/vim.py @@ -3,11 +3,14 @@ from __future__ import absolute_import import sys + +from itertools import count + +import vim + from powerline.bindings.vim import vim_get_func, vim_getvar from powerline import Powerline, FailedUnicode from powerline.lib import mergedicts -import vim -from itertools import count if not hasattr(vim, 'bindeval'): import json @@ -71,6 +74,10 @@ class VimPowerline(Powerline): self.setup_kwargs.setdefault('_local_themes', []).append((key, config)) return True + @staticmethod + def get_encoding(): + return vim.eval('&encoding') + def load_main_config(self): return _override_from(super(VimPowerline, self).load_main_config(), 'powerline_config_overrides') diff --git a/tests/test_local_overrides.vim b/tests/test_local_overrides.vim index bf2ad8f8..050e393e 100755 --- a/tests/test_local_overrides.vim +++ b/tests/test_local_overrides.vim @@ -1,4 +1,5 @@ #!/usr/bin/vim -S +set encoding=utf-8 let g:powerline_config_path = expand(':p:h:h') . '/powerline/config_files' let g:powerline_config_overrides = {'common': {'default_top_theme': 'ascii'}} let g:powerline_theme_overrides__default = {'segment_data': {'line_current_symbol': {'contents': 'LN '}, 'branch': {'before': 'B '}}} diff --git a/tests/test_plugin_file.vim b/tests/test_plugin_file.vim index 76e08bd8..6c99c5d0 100755 --- a/tests/test_plugin_file.vim +++ b/tests/test_plugin_file.vim @@ -1,5 +1,5 @@ #!/usr/bin/vim -S -set nocompatible +set encoding=utf-8 tabedit abc tabedit def try diff --git a/tests/test_tabline.vim b/tests/test_tabline.vim index 8e2cca40..42e27e76 100755 --- a/tests/test_tabline.vim +++ b/tests/test_tabline.vim @@ -1,4 +1,5 @@ #!/usr/bin/vim -S +set encoding=utf-8 source powerline/bindings/vim/plugin/powerline.vim edit abc tabedit def diff --git a/tests/vim.py b/tests/vim.py index 15cdf7b6..d8ac109f 100644 --- a/tests/vim.py +++ b/tests/vim.py @@ -9,6 +9,7 @@ options = { 'paste': 0, 'ambiwidth': 'single', 'columns': 80, + 'encoding': 'utf-8', } _last_bufnr = 0 _highlights = {}