Prevent using filter() on invalid types of values

Closes #75.
This commit is contained in:
Marco Hinz 2014-03-31 10:18:58 +02:00
parent 0bc4aae6f4
commit 110af7a38a

View file

@ -263,12 +263,15 @@ endfunction
" Function: s:show_dir {{{1 " Function: s:show_dir {{{1
function! s:show_dir(cnt) abort function! s:show_dir(cnt) abort
if empty(v:oldfiles)
return a:cnt
endif
let cnt = a:cnt let cnt = a:cnt
let num = s:numfiles let num = s:numfiles
let entries = {} let entries = {}
let cwd = getcwd()
let cwd = getcwd() let files = filter(map(copy(v:oldfiles), 'resolve(fnamemodify(v:val, ":p"))'), 'match(v:val, cwd) == 0')
let files = filter(map(copy(v:oldfiles), 'resolve(fnamemodify(v:val, ":p"))'), 'match(v:val, cwd) == 0')
if !empty(files) if !empty(files)
if exists('s:last_message') if exists('s:last_message')
@ -308,44 +311,46 @@ endfunction
" Function: s:show_files {{{1 " Function: s:show_files {{{1
function! s:show_files(cnt) abort function! s:show_files(cnt) abort
if empty(v:oldfiles)
return a:cnt
endif
if exists('s:last_message')
call s:print_section_header()
endif
let cnt = a:cnt let cnt = a:cnt
let num = s:numfiles let num = s:numfiles
let entries = {} let entries = {}
if !empty(v:oldfiles) for fname in v:oldfiles
if exists('s:last_message') let fullpath = resolve(fnamemodify(fname, ':p'))
call s:print_section_header()
" filter duplicates, bookmarks and entries from the skiplist
if has_key(entries, fullpath)
\ || !filereadable(fullpath)
\ || (exists('g:startify_skiplist') && s:is_in_skiplist(fullpath))
\ || (exists('g:startify_bookmarks') && s:is_bookmark(fullpath))
continue
endif endif
for fname in v:oldfiles let entries[fullpath] = 1
let fullpath = resolve(fnamemodify(fname, ':p')) let index = s:get_index_as_string(cnt)
" filter duplicates, bookmarks and entries from the skiplist call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname)
if has_key(entries, fullpath) execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) '<bar> call <sid>check_user_options()<cr>'
\ || !filereadable(fullpath)
\ || (exists('g:startify_skiplist') && s:is_in_skiplist(fullpath))
\ || (exists('g:startify_bookmarks') && s:is_bookmark(fullpath))
continue
endif
let entries[fullpath] = 1 let cnt += 1
let index = s:get_index_as_string(cnt) let num -= 1
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . fname) if !num
execute 'nnoremap <buffer>' index ':edit' fnameescape(fname) '<bar> call <sid>check_user_options()<cr>' break
endif
endfor
let cnt += 1 call append('$', '')
let num -= 1
if !num return cnt
break
endif
endfor
call append('$', '')
return cnt
endif
endfunction endfunction
" Function: s:show_sessions {{{1 " Function: s:show_sessions {{{1