From 8b8de32be90f69a992bbff818c6898893393aa4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Thu, 7 Feb 2013 11:42:10 +0100 Subject: [PATCH] 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. --- docs/source/overview.rst | 27 ++++++----------- powerline/bindings/vim/__init__.py | 13 -------- .../bindings/vim/{ => plugin}/powerline.vim | 30 ++++++++++++++++++- .../bindings/vim/plugin/source_plugin.vim | 11 ------- 4 files changed, 38 insertions(+), 43 deletions(-) rename powerline/bindings/vim/{ => plugin}/powerline.vim (58%) delete mode 100644 powerline/bindings/vim/plugin/source_plugin.vim diff --git a/docs/source/overview.rst b/docs/source/overview.rst index 95014013..c4c971f7 100644 --- a/docs/source/overview.rst +++ b/docs/source/overview.rst @@ -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`:: diff --git a/powerline/bindings/vim/__init__.py b/powerline/bindings/vim/__init__.py index ef46b4ae..6608372e 100644 --- a/powerline/bindings/vim/__init__.py +++ b/powerline/bindings/vim/__init__.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:') diff --git a/powerline/bindings/vim/powerline.vim b/powerline/bindings/vim/plugin/powerline.vim similarity index 58% rename from powerline/bindings/vim/powerline.vim rename to powerline/bindings/vim/plugin/powerline.vim index 9f0499f1..a7284117 100644 --- a/powerline/bindings/vim/powerline.vim +++ b/powerline/bindings/vim/plugin/powerline.vim @@ -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(":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) diff --git a/powerline/bindings/vim/plugin/source_plugin.vim b/powerline/bindings/vim/plugin/source_plugin.vim deleted file mode 100644 index ba96920e..00000000 --- a/powerline/bindings/vim/plugin/source_plugin.vim +++ /dev/null @@ -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(":h:h:h:h:h")')) - -source :h:h/powerline.vim