Improve vim plugin loading
Several of the plugin loading methods have been joined into one plugin file that will be loaded by updating the runtimepath. More informative error messages will be displayed if Python support is missing or if the module import fails. Note that this commit will break existing plugin loading, the new method with updating the runtimepath will be required. Closes #156. Closes #181.
This commit is contained in:
parent
c2e7124da0
commit
8b8de32be9
|
@ -83,26 +83,17 @@ Usage
|
|||
Vim statusline
|
||||
--------------
|
||||
|
||||
Add the following line to your :file:`vimrc`:
|
||||
Add the following line to your :file:`vimrc`, where ``{path}`` is the
|
||||
absolute path to your Powerline installation directory:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
python from powerline.bindings.vim import source_plugin; source_plugin()
|
||||
set rtp+={path}/powerline/bindings/vim
|
||||
|
||||
If you want to enable Python 3 support, substitute the ``python`` command
|
||||
above with ``python3``. Note that this is somewhat experimental as some
|
||||
segments don't have support for Python 3 yet.
|
||||
|
||||
If Powerline is installed somewhere other than Python's site-packages
|
||||
directories you'll either have to use a plugin manager like Vundle, or
|
||||
source the vim plugin file with an absolute path to the plugin location.
|
||||
|
||||
Add the following line to your :file:`vimrc`, where ``{path}`` is the path
|
||||
to the main Powerline project directory:
|
||||
|
||||
.. code-block:: vim
|
||||
|
||||
source {path}/powerline/bindings/vim/plugin/source_plugin.vim
|
||||
If you're using Vundle or Pathogen and don't want Powerline functionality in
|
||||
any other applications, simply add Powerline as a bundle and point the path
|
||||
above to the Powerline bundle directory, e.g.
|
||||
``~/.vim/bundle/powerline/powerline/bindings/vim``.
|
||||
|
||||
Shell prompts
|
||||
-------------
|
||||
|
@ -128,7 +119,7 @@ absolute path to your Powerline installation directory:
|
|||
. {path}/powerline/bindings/zsh/powerline.zsh
|
||||
|
||||
Tmux statusline
|
||||
^^^^^^^^^^^^^^^
|
||||
---------------
|
||||
|
||||
Add the following line to your :file:`tmux.conf`, where ``{path}`` is the
|
||||
absolute path to your Powerline installation directory::
|
||||
|
@ -136,7 +127,7 @@ absolute path to your Powerline installation directory::
|
|||
source '{path}/powerline/bindings/tmux/powerline.conf'
|
||||
|
||||
IPython prompt
|
||||
^^^^^^^^^^^^^^
|
||||
--------------
|
||||
|
||||
For IPython<0.11 add the following lines to your
|
||||
:file:`.ipython/ipy_user_conf.py`::
|
||||
|
|
|
@ -2,19 +2,6 @@
|
|||
|
||||
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')).decode('utf-8'))
|
||||
|
||||
try:
|
||||
_vim_globals = vim.bindeval('g:')
|
||||
|
||||
|
|
|
@ -3,11 +3,39 @@ if exists('g:powerline_loaded')
|
|||
endif
|
||||
let g:powerline_loaded = 1
|
||||
|
||||
function! s:CriticalError(message)
|
||||
echohl ErrorMsg
|
||||
echomsg a:message
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
if ! has('python') && ! has('python3')
|
||||
call s:CriticalError('You need vim compiled with Python 2.7 or 3.3+ support
|
||||
\ for Powerline to work. Please consult the documentation for more details.')
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:powerline_pycmd = substitute(get(g:, 'powerline_pycmd', 'py'), '\v^(py)%[thon](3?)$', '\1\2', '')
|
||||
let s:powerline_pyeval = get(g:, 'powerline_pyeval', s:powerline_pycmd.'eval')
|
||||
|
||||
exec s:powerline_pycmd 'import uuid'
|
||||
exec s:powerline_pycmd 'from powerline.core import Powerline'
|
||||
try
|
||||
exec s:powerline_pycmd 'from powerline.core import Powerline'
|
||||
catch
|
||||
" An error occured while importing the module, it could be installed
|
||||
" outside of Python's module search paths. Update sys.path and try again.
|
||||
exec s:powerline_pycmd 'import sys, vim'
|
||||
exec s:powerline_pycmd 'sys.path.append(vim.eval(''expand("<sfile>:h:h:h:h:h")''))'
|
||||
try
|
||||
exec s:powerline_pycmd 'from powerline.core import Powerline'
|
||||
catch
|
||||
call s:CriticalError('An error occured while importing the Powerline package.
|
||||
\ This could be caused by an invalid sys.path setting, or by an incompatible
|
||||
\ Python version (Powerline requires Python 2.7 or 3.3+ to work). Please consult
|
||||
\ the troubleshooting section in the documentation for possible solutions.')
|
||||
finish
|
||||
endtry
|
||||
endtry
|
||||
exec s:powerline_pycmd 'powerline = Powerline("vim")'
|
||||
|
||||
if exists('*'. s:powerline_pyeval)
|
|
@ -1,11 +0,0 @@
|
|||
if ! has('python') && ! has('python3')
|
||||
echohl ErrorMsg
|
||||
echomsg 'You need vim compiled with Python 3.3 or Python 2.7 support for Powerline to work. Please consult the documentation for more details.'
|
||||
echohl None
|
||||
finish
|
||||
endif
|
||||
|
||||
python import sys, vim
|
||||
python sys.path.append(vim.eval('expand("<sfile>:h:h:h:h:h")'))
|
||||
|
||||
source <sfile>:h:h/powerline.vim
|
Loading…
Reference in New Issue