improve s:map: precisely detect the version

This commit is contained in:
itchyny
2016-04-08 09:24:06 +09:00
parent 402d502b92
commit 7945e6fd90

View File

@@ -2,7 +2,7 @@
" Filename: autoload/lightline.vim " Filename: autoload/lightline.vim
" Author: itchyny " Author: itchyny
" License: MIT License " License: MIT License
" Last Change: 2016/04/08 09:00:37. " Last Change: 2016/04/08 09:23:19.
" ============================================================================= " =============================================================================
let s:save_cpo = &cpo let s:save_cpo = &cpo
@@ -401,14 +401,13 @@ function! s:flatten_twice(xss) abort
return ys return ys
endfunction endfunction
if v:version >= 703 if v:version > 702 || v:version == 702 && has('patch295')
let s:map = function('map') let s:map = function('map')
else else
function! s:map(xs, f) abort function! s:map(xs, f) abort
let ys = [] let ys = []
for i in range(len(a:xs)) for i in range(len(a:xs))
let g = substitute(a:f, 'v:key', i, 'g') call extend(ys, map(a:xs[i:i], substitute(a:f, 'v:key', i, 'g')))
call extend(ys, map(a:xs[i:i], g))
endfor endfor
return ys return ys
endfunction endfunction