Fix various Python 3 related issues
Powerline now detects the Python version and verifies that the user has Python 3.3 before enabling Python 3 support. To enable Python 3 support, use `python3` to execute source_plugin() in your vimrc instead of `python2`.
This commit is contained in:
parent
85331710bf
commit
a620a0ef54
|
@ -4,9 +4,16 @@ import vim
|
|||
|
||||
|
||||
def source_plugin():
|
||||
import sys
|
||||
import os
|
||||
if sys.version_info[:2] == (3, 3):
|
||||
vim.command('let g:powerline_pycmd = "python3"')
|
||||
vim.command('let g:powerline_pyeval = "py3eval"')
|
||||
else:
|
||||
vim.command('let g:powerline_pycmd = "python"')
|
||||
vim.command('let g:powerline_pyeval = "pyeval"')
|
||||
fnameescape = vim_get_func('fnameescape')
|
||||
vim.command('source ' + fnameescape(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'powerline.vim')))
|
||||
vim.command('source ' + fnameescape(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'powerline.vim')).decode('utf-8'))
|
||||
|
||||
try:
|
||||
_vim_globals = vim.bindeval('g:')
|
||||
|
|
|
@ -5,9 +5,9 @@ if ! has('python') && ! has('python3')
|
|||
finish
|
||||
endif
|
||||
|
||||
let s:pycmd = has('python3') ? 'python3' : 'python'
|
||||
|
||||
exec s:pycmd ' import sys, vim'
|
||||
exec s:pycmd ' sys.path.append(vim.eval(''expand("<sfile>:h:h:h:h:h")''))'
|
||||
|
||||
source <sfile>:h:h/powerline.vim
|
||||
python <<EOF
|
||||
import sys, vim
|
||||
sys.path.append(vim.eval('expand("<sfile>:h:h:h:h:h")'))
|
||||
from powerline.bindings.vim import source_plugin
|
||||
source_plugin()
|
||||
EOF
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
let s:pycmd = has('python3') ? 'python3' : 'python'
|
||||
exec g:powerline_pycmd 'import uuid'
|
||||
exec g:powerline_pycmd 'from powerline.core import Powerline'
|
||||
exec g:powerline_pycmd 'powerline = Powerline("vim")'
|
||||
|
||||
exec s:pycmd ' import uuid'
|
||||
exec s:pycmd ' from powerline.core import Powerline'
|
||||
exec s:pycmd ' powerline = Powerline("vim")'
|
||||
|
||||
if exists('*py3eval')
|
||||
let s:pyeval = function('py3eval')
|
||||
elseif exists('*pyeval')
|
||||
let s:pyeval = function('pyeval')
|
||||
if exists('*'. g:powerline_pyeval)
|
||||
let s:pyeval = function(g:powerline_pyeval)
|
||||
else
|
||||
exec s:pycmd ' import json, vim'
|
||||
exec g:powerline_pycmd 'import json, vim'
|
||||
function! s:pyeval(e)
|
||||
exec s:pycmd ' vim.command("return " + json.dumps(eval(vim.eval("a:e"))))'
|
||||
exec g:powerline_pycmd 'vim.command("return " + json.dumps(eval(vim.eval("a:e"))))'
|
||||
endfunction
|
||||
endif
|
||||
|
||||
|
|
|
@ -5,6 +5,12 @@ import copy
|
|||
|
||||
from .segment import Segment
|
||||
|
||||
try:
|
||||
unicode()
|
||||
except NameError:
|
||||
unicode = str
|
||||
|
||||
|
||||
class Theme(object):
|
||||
def __init__(self, ext, colorscheme, theme_config, common_config):
|
||||
self.colorscheme = colorscheme
|
||||
|
@ -12,7 +18,7 @@ class Theme(object):
|
|||
self.segments = []
|
||||
self.EMPTY_SEGMENT = {
|
||||
'contents': None,
|
||||
'highlight': defaultdict(lambda : {'fg': False, 'bg': False, 'attr': 0})
|
||||
'highlight': defaultdict(lambda: {'fg': False, 'bg': False, 'attr': 0})
|
||||
}
|
||||
get_segment = Segment(ext, common_config['paths'], colorscheme, theme_config.get('default_module')).get
|
||||
for side in ['left', 'right']:
|
||||
|
@ -42,11 +48,7 @@ class Theme(object):
|
|||
pass
|
||||
else:
|
||||
continue
|
||||
try:
|
||||
contents = unicode(segment['contents'])
|
||||
except NameError:
|
||||
contents = str(segment['contents'])
|
||||
segment['contents'] = (segment['before'] + contents + segment['after'])\
|
||||
segment['contents'] = (segment['before'] + unicode(segment['contents']) + segment['after'])\
|
||||
.ljust(segment['ljust'])\
|
||||
.rjust(segment['rjust'])
|
||||
# We need to yield a copy of the segment, or else mode-dependent
|
||||
|
|
Loading…
Reference in New Issue