소스 검색

Prevent using filter() on invalid types of values

Closes #75.
Marco Hinz 11 년 전
부모
커밋
110af7a38a
1개의 변경된 파일35개의 추가작업 그리고 30개의 파일을 삭제
  1. 35 30
      autoload/startify.vim

+ 35 - 30
autoload/startify.vim

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