implement s:unique for environment where uniq() is not available

This commit is contained in:
itchyny
2016-03-24 21:26:14 +09:00
parent c89e1d8007
commit e6c5ad3215

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/03/24 21:15:04. " Last Change: 2016/03/24 21:22:33.
" ============================================================================= " =============================================================================
let s:save_cpo = &cpo let s:save_cpo = &cpo
@@ -255,9 +255,26 @@ function! s:term(l) abort
return len(a:l) == 5 && type(a:l[4]) == 1 && strlen(a:l[4]) ? 'term='.a:l[4].' cterm='.a:l[4].' gui='.a:l[4] : '' return len(a:l) == 5 && type(a:l[4]) == 1 && strlen(a:l[4]) ? 'term='.a:l[4].' cterm='.a:l[4].' gui='.a:l[4] : ''
endfunction endfunction
function! s:unique(xs) abort if exists('*uniq')
return uniq(sort(copy(a:xs))) function! s:unique(xs) abort
endfunction return uniq(sort(a:xs))
endfunction
else
function! s:unique(xs) abort
call sort(a:xs)
let i = 0
let l = len(a:xs) - 1
while i < l
if a:xs[i] ==# a:xs[i + 1]
call remove(a:xs, i + 1)
let l -= 1
else
let i += 1
endif
endwhile
return a:xs
endfunction
endif
function! lightline#highlight(...) abort function! lightline#highlight(...) abort
let [c, f, g] = [s:lightline.palette, s:lightline.mode_fallback, s:lightline.component_type] let [c, f, g] = [s:lightline.palette, s:lightline.mode_fallback, s:lightline.component_type]