Use &encoding as powerline encoding in Vim

Among other benefits (i.e. correct fall back to ascii theme when Vim uses
non-unicode encoding) this should also fix travis tests: apparently travis is
not setting LANG or similar environment variables to some unicode locale, so
tests are failing.
This commit is contained in:
ZyX 2014-08-27 23:42:04 +04:00
parent 8f70811768
commit 9658e45eee
7 changed files with 25 additions and 7 deletions

View File

@ -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

View File

@ -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')

View File

@ -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')

View File

@ -1,4 +1,5 @@
#!/usr/bin/vim -S
set encoding=utf-8
let g:powerline_config_path = expand('<sfile>: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 '}}}

View File

@ -1,5 +1,5 @@
#!/usr/bin/vim -S
set nocompatible
set encoding=utf-8
tabedit abc
tabedit def
try

View File

@ -1,4 +1,5 @@
#!/usr/bin/vim -S
set encoding=utf-8
source powerline/bindings/vim/plugin/powerline.vim
edit abc
tabedit def

View File

@ -9,6 +9,7 @@ options = {
'paste': 0,
'ambiwidth': 'single',
'columns': 80,
'encoding': 'utf-8',
}
_last_bufnr = 0
_highlights = {}