소스 검색

Refactor headers and footers

g:startify_custom_header and g:startify_custom_footer behave the same now.

Prior to this change, g:startify_custom_footer only accepted lists and no
strings containing expressions that evaluate to lists.

References #316
Marco Hinz 7 년 전
부모
커밋
c1a81780d5
1개의 변경된 파일19개의 추가작업 그리고 16개의 파일을 삭제
  1. 19 16
      autoload/startify.vim

+ 19 - 16
autoload/startify.vim

@@ -82,20 +82,9 @@ function! startify#insane_in_the_membrane() abort
   endif
 
   " Must be global so that it can be read by syntax/startify.vim.
-  if exists('g:startify_custom_header')
-    if type(g:startify_custom_header) == type([])
-      let g:startify_header = copy(g:startify_custom_header)
-    elseif type(g:startify_custom_header) == type('')
-      let g:startify_header = empty(g:startify_custom_header)
-            \ ? []
-            \ : eval(g:startify_custom_header)
-    else
-      echomsg 'startify: wrong type of value for g:startify_custom_header'
-      let g:startify_header = startify#fortune#cowsay()
-    endif
-  else
-    let g:startify_header = startify#fortune#cowsay()
-  endif
+  let g:startify_header = exists('g:startify_custom_header')
+        \ ? s:set_custom_section(g:startify_custom_header)
+        \ : startify#fortune#cowsay()
   if !empty(g:startify_header)
     let g:startify_header += ['']  " add blank line
   endif
@@ -146,9 +135,13 @@ function! startify#insane_in_the_membrane() abort
 
   let b:startify.lastline = line('$')
 
-  if exists('g:startify_custom_footer')
-    call append('$', g:startify_custom_footer)
+  let footer = exists('g:startify_custom_footer')
+        \ ? s:set_custom_section(g:startify_custom_footer)
+        \ : []
+  if !empty(footer)
+    let footer = [''] + footer
   endif
+  call append('$', footer)
 
   setlocal nomodifiable nomodified
 
@@ -528,6 +521,16 @@ function! s:open_buffer(entry)
   endif
 endfunction
 
+" Function: s:set_custom_section {{{1
+function! s:set_custom_section(section) abort
+  if type(a:section) == type([])
+    return a:section
+  elseif type(a:section) == type('')
+    return empty(a:section) ? [] : eval(a:section)
+  endif
+  return []
+endfunction
+
 " Function: s:display_by_path {{{1
 function! s:display_by_path(path_prefix, path_format, use_env) abort
   let oldfiles = call(get(g:, 'startify_enable_unsafe') ? 's:filter_oldfiles_unsafe' : 's:filter_oldfiles',