From 20c2a166717268773fac4f1fd5be23a7c06f24e9 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 27 Jan 2015 11:16:06 -0800 Subject: [PATCH] [vim] Load Powerline the official way https://powerline.readthedocs.org/en/latest/usage/other.html#vim-statusline --- .vim/bundle/powerline/__init__.py | 157 --------------------- .vim/bundle/powerline/__init__.pyc | Bin 5835 -> 0 bytes .vim/bundle/powerline/plugin/powerline.vim | 89 ------------ .vimrc | 5 + 4 files changed, 5 insertions(+), 246 deletions(-) delete mode 100644 .vim/bundle/powerline/__init__.py delete mode 100644 .vim/bundle/powerline/__init__.pyc delete mode 100644 .vim/bundle/powerline/plugin/powerline.vim diff --git a/.vim/bundle/powerline/__init__.py b/.vim/bundle/powerline/__init__.py deleted file mode 100644 index 5ee5225..0000000 --- a/.vim/bundle/powerline/__init__.py +++ /dev/null @@ -1,157 +0,0 @@ -# vim:fileencoding=utf-8:noet - -import sys -import codecs - -try: - import vim -except ImportError: - vim = {} - -if hasattr(vim, 'bindeval'): - def vim_get_func(f, rettype=None): - '''Return a vim function binding.''' - try: - func = vim.bindeval('function("' + f + '")') - if sys.version_info >= (3,) and rettype is str: - return (lambda *args, **kwargs: func(*args, **kwargs).decode('utf-8', errors='replace')) - return func - except vim.error: - return None -else: - import json - - class VimFunc(object): - '''Evaluate a vim function using vim.eval(). - - This is a fallback class for older vim versions. - ''' - __slots__ = ('f', 'rettype') - - def __init__(self, f, rettype=None): - self.f = f - self.rettype = rettype - - def __call__(self, *args): - r = vim.eval(self.f + '(' + json.dumps(args)[1:-1] + ')') - if self.rettype: - return self.rettype(r) - return r - - vim_get_func = VimFunc - - -# It may crash on some old vim versions and I do not remember in which patch -# I fixed this crash. -if hasattr(vim, 'vvars') and vim.vvars['version'] > 703: - _vim_to_python_types = { - vim.Dictionary: lambda value: dict(((key, _vim_to_python(value[key])) for key in value.keys())), - vim.List: lambda value: [_vim_to_python(item) for item in value], - vim.Function: lambda _: None, - } - - _id = lambda value: value - - def _vim_to_python(value): - return _vim_to_python_types.get(type(value), _id)(value) - - def vim_getvar(varname): - return _vim_to_python(vim.vars[str(varname)]) - - def bufvar_exists(buffer, varname): - buffer = buffer or vim.current.buffer - return varname in buffer.vars - - def vim_getwinvar(segment_info, varname): - return _vim_to_python(segment_info['window'].vars[str(varname)]) -else: - _vim_exists = vim_get_func('exists', rettype=int) - - def vim_getvar(varname): # NOQA - varname = 'g:' + varname - if _vim_exists(varname): - return vim.eval(varname) - else: - raise KeyError(varname) - - def bufvar_exists(buffer, varname): # NOQA - if not buffer or buffer.number == vim.current.buffer.number: - return vim.eval('exists("b:{0}")'.format(varname)) - else: - return vim.eval('has_key(getbufvar({0}, ""), {1})' - .format(buffer.number, varname)) - - def vim_getwinvar(segment_info, varname): # NOQA - result = vim.eval('getwinvar({0}, "{1}")'.format(segment_info['winnr'], varname)) - if result == '': - if not int(vim.eval('has_key(getwinvar({0}, ""), "{1}")'.format(segment_info['winnr'], varname))): - raise KeyError(varname) - return result - -if hasattr(vim, 'options'): - def vim_getbufoption(info, option): - return info['buffer'].options[str(option)] -else: - def vim_getbufoption(info, option): # NOQA - return getbufvar(info['bufnr'], '&' + option) - - -if sys.version_info < (3,) or not hasattr(vim, 'bindeval'): - getbufvar = vim_get_func('getbufvar') -else: - _getbufvar = vim_get_func('getbufvar') - - def getbufvar(*args): - r = _getbufvar(*args) - if type(r) is bytes: - return r.decode('utf-8') - return r - - -class VimEnviron(object): - @staticmethod - def __getitem__(key): - return vim.eval('$' + key) - - @staticmethod - def get(key, default=None): - return vim.eval('$' + key) or default - - @staticmethod - def __setitem__(key, value): - return vim.command('let $' + key + '="' - + value.replace('"', '\\"').replace('\\', '\\\\').replace('\n', '\\n').replace('\0', '') - + '"') - - -if sys.version_info < (3,): - def buffer_name(buf): - return buf.name -else: - vim_bufname = vim_get_func('bufname') - - def buffer_name(buf): # NOQA - try: - name = buf.name - except UnicodeDecodeError: - return vim_bufname(buf.number) - else: - return name.encode('utf-8') if name else None - - -vim_strtrans = vim_get_func('strtrans') - - -def powerline_vim_strtrans_error(e): - if not isinstance(e, UnicodeDecodeError): - raise NotImplementedError - # Assuming &encoding is utf-8 strtrans should not return anything but ASCII - # under current circumstances - text = vim_strtrans(e.object[e.start:e.end]).decode() - return (text, e.end) - - -codecs.register_error('powerline_vim_strtrans_error', powerline_vim_strtrans_error) - - -environ = VimEnviron() diff --git a/.vim/bundle/powerline/__init__.pyc b/.vim/bundle/powerline/__init__.pyc deleted file mode 100644 index d4e6220f7fce92c049846a36a210bb372f90b186..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5835 zcmcgwTW=f36+W}1D3YcuS+>O}c56m)3#w_Pv`q{*aE!v1;|6W{uu7eTaJ*e{m-0&F zF0-?8Odv*q+GtXs$lvK>e@~wK1KRI9vn1s{^oHE;j=ak-m}7(zaA%PfnYXe;~$~1hb5!Mm~=#5*vv;dFe_1 zDR+n}@(Qa~B<;>NsY$;kQB~qq8DheUyb^gS@-c3!LCux29gCb?k?2i1h2S2V^8#q)j|_L;!oJeKD(O`{ z%yqXUYU>tPC3<5fifxXlDB2RY+3LSRAs%+GK`+U_@z*QrXdWeL6h8|`0}mY*>aK!f z2dJhGr2tuwt&wj;+R#TEB>YXJ@Zui53s*S4rRpjtHl+QqK zmHVuyrk_yLP}bq+th%c_?8m75xH!wxPS|;tj61`#bWkK&+982Sdc0?wm@*sf?pV^g zvkUc!kW!_+ir*V3_Btw@43a_E_c&QG2=( zd`fE>{3(&iI5>`rfP%chb1tG1uVUKfnprb-vtg8~N6GkOOi|tI3{>|}>@F(U68uPn z8Y*9rz9JR6cMc?~s=d_2FVXiWEO`JUI17uo^I!Novp^pqxkoeU?(Q|4jmD=>6WhUm z*cpbS(NQ=!?F>etwVh#>cd}6w=L+Id;C2s7eDdM1qZ&{_EJV|N6uX5AKm}X_G(2r6 z`G+d+p5kt?L6?hFT{a#K&y8bPmI}TZ7-_DSa2L}s144x)5lRnH>~B#yzX6s`paLUp z0PdtpF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X(@4GXSg`R`Ig8QujaX1mCxrd z|2ist5wS&BB!h8`OF-l^TDbcYRpB3?T4-Eb%P{skIOYo!cYiYL)rwiKs3Ey09l9Hz z?%2tfD*I$S$?`&@slxMVXv3n&9qo({zJgvO($PsgDD;x%?lO8QqrW@AtpZ^%%%>W| zevcGE<1`;t_`%=hMn7l8JW1oJCTK}o_{^!*Q~TUX-LwB8TjWM*ik+KUz5v~$n7bL@ zB@WdQw(wxI0k7Hg*3Eje:h:h:h:h:h\")'))\n" - let s:pystr .= " ".s:import_cmd."\n" - execute s:pycmd s:pystr - unlet s:pystr - let s:launched = 1 -finally - unlet s:import_cmd - if !exists('s:launched') - echohl ErrorMsg - echomsg 'An error occurred while importing powerline package.' - echomsg 'This could be caused by invalid sys.path setting,' - echomsg 'or by an incompatible Python version (powerline requires' - echomsg 'Python 2.6, 2.7 or 3.2 and later to work). Please consult' - echomsg 'the troubleshooting section in the documentation for' - echomsg 'possible solutions.' - echohl None - let s:pystr = "def powerline_troubleshoot():\n" - let s:pystr .= " import sys\n" - let s:pystr .= " if sys.version_info < (2, 6):\n" - let s:pystr .= " print('Too old python version: ' + sys.version + ' (first supported is 2.6)')\n" - let s:pystr .= " elif sys.version_info[0] == 3 and sys.version_info[1] < 2:\n" - let s:pystr .= " print('Too old python 3 version: ' + sys.version + ' (first supported is 3.2)')\n" - let s:pystr .= " try:\n" - let s:pystr .= " import powerline\n" - let s:pystr .= " except ImportError:\n" - let s:pystr .= " print('Unable to import powerline, is it installed?')\n" - if expand('')[:4] isnot# '/usr/' - let s:pystr .= " else:\n" - let s:pystr .= " import os\n" - let s:pystr .= " powerline_dir = os.path.dirname(os.path.realpath(powerline.__file__))\n" - let s:pystr .= " this_dir = os.path.dirname(os.path.realpath(vim.eval('expand(\":p\")')))\n" - let s:pystr .= " this_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir)))\n" - let s:pystr .= " if os.path.basename(this_dir) != 'powerline':\n" - let s:pystr .= " print('Check your installation:')\n" - let s:pystr .= " print('this script is not in powerline[/bindings/vim/plugin] directory,')\n" - let s:pystr .= " print('neither it is installed system-wide')\n" - let s:pystr .= " this_dir = os.path.dirname(this_dir)\n" - let s:pystr .= " real_powerline_dir = os.path.realpath(powerline_dir)\n" - let s:pystr .= " real_this_dir = os.path.realpath(this_dir)\n" - let s:pystr .= " if real_this_dir != sys.path[-1]:\n" - let s:pystr .= " print('Check your installation:')\n" - let s:pystr .= " print('this script is symlinked somewhere where powerline is not present.')\n" - let s:pystr .= " elif real_powerline_dir != real_this_dir:\n" - let s:pystr .= " print('It appears that you have two powerline versions installed:')\n" - let s:pystr .= " print('one in ' + real_powerline_dir + ', other in ' + real_this_dir + '.')\n" - let s:pystr .= " print('You should remove one of this. Check out troubleshooting section,')\n" - let s:pystr .= " print('it contains some information about the alternatives.')\n" - endif - execute s:pycmd s:pystr - unlet s:pystr - unlet s:pycmd - unlet s:pyeval - finish - else - unlet s:launched - endif -endtry - -execute s:pycmd 'import vim' -execute s:pycmd 'powerline_setup(pyeval=vim.eval("s:pyeval"), pycmd=vim.eval("s:pycmd"))' -execute s:pycmd 'del powerline_setup' - -unlet s:pycmd -unlet s:pyeval diff --git a/.vimrc b/.vimrc index a42b4e1..a0732be 100644 --- a/.vimrc +++ b/.vimrc @@ -238,6 +238,11 @@ nmap vwi VimwikiDiaryGenerateLinks " NERDCommenter let NERDSpaceDelims = 1 +" Powerline +python from powerline.vim import setup as powerline_setup +python powerline_setup() +python del powerline_setup + " gui stuff set guioptions-=T set guifont=Consolas:h9:cANSI