Replace let s:pystr… with call s:rcmd(…)

Makes lines slightly shorter
This commit is contained in:
ZyX 2014-08-24 13:21:09 +04:00
parent 098dadadf5
commit c2609e31b8

View File

@ -52,19 +52,27 @@ endif
unlet s:has_python unlet s:has_python
let s:import_cmd = 'from powerline.vim import VimPowerline' let s:import_cmd = 'from powerline.vim import VimPowerline'
function s:rcmd(s)
if !exists('s:pystr')
let s:pystr = a:s . "\n"
else
let s:pystr = s:pystr . a:s . "\n"
endif
endfunction
try try
let s:pystr = "try:\n" call s:rcmd("try:")
let s:pystr .= " ".s:import_cmd."\n" call s:rcmd(" ".s:import_cmd."")
let s:pystr .= "except ImportError:\n" call s:rcmd("except ImportError:")
let s:pystr .= " import sys, vim\n" call s:rcmd(" import sys, vim")
let s:pystr .= " sys.path.append(vim.eval('expand(\"<sfile>:h:h:h:h:h\")'))\n" call s:rcmd(" sys.path.append(vim.eval('expand(\"<sfile>:h:h:h:h:h\")'))")
let s:pystr .= " ".s:import_cmd."\n" call s:rcmd(" ".s:import_cmd."")
execute s:pycmd s:pystr execute s:pycmd s:pystr
unlet s:pystr unlet s:pystr
let s:launched = 1 let s:launched = 1
finally finally
unlet s:import_cmd unlet s:import_cmd
if !exists('s:launched') if !exists('s:launched')
unlet s:pystr
echohl ErrorMsg echohl ErrorMsg
echomsg 'An error occurred while importing powerline package.' echomsg 'An error occurred while importing powerline package.'
echomsg 'This could be caused by invalid sys.path setting,' echomsg 'This could be caused by invalid sys.path setting,'
@ -77,46 +85,48 @@ finally
echomsg 'should set g:powerline_pycmd to "py3" to make it load correctly.' echomsg 'should set g:powerline_pycmd to "py3" to make it load correctly.'
endif endif
echohl None echohl None
let s:pystr = "def powerline_troubleshoot():\n" call s:rcmd( "def powerline_troubleshoot():")
let s:pystr .= " import sys\n" call s:rcmd( " import sys")
let s:pystr .= " if sys.version_info < (2, 6):\n" call s:rcmd( " if sys.version_info < (2, 6):")
let s:pystr .= " print('Too old python version: ' + sys.version + ' (first supported is 2.6)')\n" call s:rcmd( " print('Too old python version: ' + sys.version + ' (first supported is 2.6)')")
let s:pystr .= " elif sys.version_info[0] == 3 and sys.version_info[1] < 2:\n" call s:rcmd( " elif sys.version_info[0] == 3 and sys.version_info[1] < 2:")
let s:pystr .= " print('Too old python 3 version: ' + sys.version + ' (first supported is 3.2)')\n" call s:rcmd( " print('Too old python 3 version: ' + sys.version + ' (first supported is 3.2)')")
let s:pystr .= " try:\n" call s:rcmd( " try:")
let s:pystr .= " import powerline\n" call s:rcmd( " import powerline")
let s:pystr .= " except ImportError:\n" call s:rcmd( " except ImportError:")
let s:pystr .= " print('Unable to import powerline, is it installed?')\n" call s:rcmd( " print('Unable to import powerline, is it installed?')")
if expand('<sfile>')[:4] isnot# '/usr/' if strpart(expand('<sfile>'), 0, 5) !=# '/usr/'
let s:pystr .= " else:\n" call s:rcmd(" else:")
let s:pystr .= " import os\n" call s:rcmd(" import os")
let s:pystr .= " powerline_dir = os.path.dirname(os.path.realpath(powerline.__file__))\n" call s:rcmd(" powerline_dir = os.path.dirname(os.path.realpath(powerline.__file__))")
let s:pystr .= " this_dir = os.path.dirname(os.path.realpath(vim.eval('expand(\"<sfile>:p\")')))\n" call s:rcmd(" this_dir = os.path.dirname(os.path.realpath(vim.eval('expand(\"<sfile>:p\")')))")
let s:pystr .= " this_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir)))\n" call s:rcmd(" this_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_dir)))")
let s:pystr .= " if os.path.basename(this_dir) != 'powerline':\n" call s:rcmd(" if os.path.basename(this_dir) != 'powerline':")
let s:pystr .= " print('Check your installation:')\n" call s:rcmd(" print('Check your installation:')")
let s:pystr .= " print('this script is not in powerline[/bindings/vim/plugin] directory,')\n" call s:rcmd(" print('this script is not in powerline[/bindings/vim/plugin] directory,')")
let s:pystr .= " print('neither it is installed system-wide')\n" call s:rcmd(" print('neither it is installed system-wide')")
let s:pystr .= " this_dir = os.path.dirname(this_dir)\n" call s:rcmd(" this_dir = os.path.dirname(this_dir)")
let s:pystr .= " real_powerline_dir = os.path.realpath(powerline_dir)\n" call s:rcmd(" real_powerline_dir = os.path.realpath(powerline_dir)")
let s:pystr .= " real_this_dir = os.path.realpath(this_dir)\n" call s:rcmd(" real_this_dir = os.path.realpath(this_dir)")
let s:pystr .= " if real_this_dir != sys.path[-1]:\n" call s:rcmd(" if real_this_dir != sys.path[-1]:")
let s:pystr .= " print('Check your installation:')\n" call s:rcmd(" print('Check your installation:')")
let s:pystr .= " print('this script is symlinked somewhere where powerline is not present.')\n" call s:rcmd(" print('this script is symlinked somewhere where powerline is not present.')")
let s:pystr .= " elif real_powerline_dir != real_this_dir:\n" call s:rcmd(" elif real_powerline_dir != real_this_dir:")
let s:pystr .= " print('It appears that you have two powerline versions installed:')\n" call s:rcmd(" print('It appears that you have two powerline versions installed:')")
let s:pystr .= " print('one in ' + real_powerline_dir + ', other in ' + real_this_dir + '.')\n" call s:rcmd(" print('one in ' + real_powerline_dir + ', other in ' + real_this_dir + '.')")
let s:pystr .= " print('You should remove one of this. Check out troubleshooting section,')\n" call s:rcmd(" print('You should remove one of this. Check out troubleshooting section,')")
let s:pystr .= " print('it contains some information about the alternatives.')\n" call s:rcmd(" print('it contains some information about the alternatives.')")
endif endif
execute s:pycmd s:pystr execute s:pycmd s:pystr
unlet s:pystr unlet s:pystr
unlet s:pycmd unlet s:pycmd
unlet s:pyeval unlet s:pyeval
delfunction s:rcmd
finish finish
else else
unlet s:launched unlet s:launched
endif endif
delfunction s:rcmd
endtry endtry
let s:can_replace_pyeval = !exists('g:powerline_pyeval') let s:can_replace_pyeval = !exists('g:powerline_pyeval')