Parcourir la source

Show random quotes if g:startify_custom_header isn't set

Marco Hinz il y a 9 ans
Parent
commit
fa733c3e20
3 fichiers modifiés avec 23 ajouts et 31 suppressions
  1. 8 7
      autoload/startify.vim
  2. 14 21
      doc/startify.txt
  3. 1 3
      syntax/startify.vim

+ 8 - 7
autoload/startify.vim

@@ -67,9 +67,12 @@ function! startify#insane_in_the_membrane() abort
     setlocal norelativenumber
     setlocal norelativenumber
   endif
   endif
 
 
-  if exists('g:startify_custom_header')
-    call append('$', g:startify_custom_header)
-  endif
+  " Must be global so that it can be read by syntax/startify.vim.
+  let g:startify_header = exists('g:startify_custom_header')
+        \ ? copy(g:startify_custom_header)
+        \ : startify#fortune#get_random_quote()
+  let g:startify_header += ['']  " add blank line
+  call append('$', g:startify_header)
 
 
   let s:tick = 0
   let s:tick = 0
   let s:entries = {}
   let s:entries = {}
@@ -124,10 +127,7 @@ function! startify#insane_in_the_membrane() abort
 
 
   " compute first line offset
   " compute first line offset
   let s:firstline = 2
   let s:firstline = 2
-  " increase offset if there is a custom header
-  if exists('g:startify_custom_header')
-    let s:firstline += len(g:startify_custom_header)
-  endif
+  let s:firstline += len(g:startify_header)
   " no special, no local Session.vim, but a section header
   " no special, no local Session.vim, but a section header
   if !s:show_special && !exists('l:show_session') && type(s:lists[0]) == 3
   if !s:show_special && !exists('l:show_session') && type(s:lists[0]) == 3
     let s:firstline += len(s:lists[0]) + 1
     let s:firstline += len(s:lists[0]) + 1
@@ -826,3 +826,4 @@ function! s:init_env()
   let s:env = sort(s:env, 's:compare_by_key_len')
   let s:env = sort(s:env, 's:compare_by_key_len')
   let s:env = sort(s:env, 's:compare_by_val_len')
   let s:env = sort(s:env, 's:compare_by_val_len')
 endfunction
 endfunction
+

+ 14 - 21
doc/startify.txt

@@ -1,4 +1,4 @@
-*startify.txt*  Showing recently used stuff like a boss.
+*startify.txt*  The fancy start screen.
 *startify*
 *startify*
                 __                    __           ___
                 __                    __           ___
                /\ \__                /\ \__  __  /'___\
                /\ \__                /\ \__  __  /'___\
@@ -10,10 +10,6 @@
                                                              /\___/
                                                              /\___/
                                                              \/__/
                                                              \/__/
   by Marco Hinz~
   by Marco Hinz~
-
-  Twitter: https://twitter.com/_mhinz_
-  Github:  http://github.com/mhinz
-  IRC:     mhi^ (Freenode)
 >
 >
   If you use any of my plugins, please star them on github. It's a great way
   If you use any of my plugins, please star them on github. It's a great way
   of getting feedback and gives me the kick to put more time into their
   of getting feedback and gives me the kick to put more time into their
@@ -424,19 +420,17 @@ NOTE: There is no sanitizing going on, so you should know what you're doing!
 ------------------------------------------------------------------------------
 ------------------------------------------------------------------------------
                                                       *g:startify_custom_header*
                                                       *g:startify_custom_header*
 >
 >
-    let g:startify_custom_header = ''
+    let g:startify_custom_header = startify#fortune#get_random_quote()
 <
 <
-This is a list of single-quoted strings to be shown before everything else.
-Every string will be written on its own line.
-
-NOTE: If a string contains ', you have to quote it with another '.
+This is a list of strings to be shown before everything else. Every string
+will be written on its own line, hence you can use empty strings for blank
+lines.
 
 
-A programmatic example:
+Simple example:~
 >
 >
-    let g:startify_custom_header =
-      \ map(split(system('fortune | cowsay'), '\n'), '"   ". v:val') + ['','']
+    let g:startify_custom_header = ['line 1', '', 'line 3']
 <
 <
-A hardcoded example:
+More complex example:~
 >
 >
     let g:startify_custom_header = [
     let g:startify_custom_header = [
             \ '                                 ________  __ __        ',
             \ '                                 ________  __ __        ',
@@ -446,11 +440,13 @@ A hardcoded example:
             \ '   \ \ \_/ |\ \ \/\ \/\ \/\ \      /'' /''__  \ \__ ,__\',
             \ '   \ \ \_/ |\ \ \/\ \/\ \/\ \      /'' /''__  \ \__ ,__\',
             \ '    \ \___/  \ \_\ \_\ \_\ \_\    /\_/ /\_\  \/_/\_\_/  ',
             \ '    \ \___/  \ \_\ \_\ \_\ \_\    /\_/ /\_\  \/_/\_\_/  ',
             \ '     \/__/    \/_/\/_/\/_/\/_/    \//  \/_/     \/_/    ',
             \ '     \/__/    \/_/\/_/\/_/\/_/    \//  \/_/     \/_/    ',
-            \ '',
-            \ '',
             \ ]
             \ ]
 <
 <
-
+Programmatic example:~
+>
+    let g:startify_custom_header =
+            \ map(split(system('fortune | cowsay'), '\n'), '"   ". v:val')
+<
 Also have a look at |startify-faq-08|.
 Also have a look at |startify-faq-08|.
 
 
 ------------------------------------------------------------------------------
 ------------------------------------------------------------------------------
@@ -760,7 +756,7 @@ How to use the output of a command as header?~
     redir END
     redir END
 
 
     let g:startify_custom_header =
     let g:startify_custom_header =
-        \ map(split(test), 'repeat(" ", 10) . v:val') + ['']
+        \ map(split(test), 'repeat(" ", 10) . v:val')
 <
 <
 |:redir| puts a string into 'test'. Then we turn it into a list of strings.
 |:redir| puts a string into 'test'. Then we turn it into a list of strings.
 Then we shift each string to the right by 10 spaces. Afterwards we add an
 Then we shift each string to the right by 10 spaces. Afterwards we add an
@@ -841,9 +837,6 @@ This is my configuration..
     let g:startify_custom_footer =
     let g:startify_custom_footer =
           \ ['', "   Vim is charityware. Please read ':help uganda'.", '']
           \ ['', "   Vim is charityware. Please read ':help uganda'.", '']
 
 
-    let g:startify_custom_header =
-          \ map(split(system('tips | cowsay -f apt'), '\n'), '"   ". v:val') + ['']
-
     hi StartifyBracket ctermfg=240
     hi StartifyBracket ctermfg=240
     hi StartifyFile    ctermfg=147
     hi StartifyFile    ctermfg=147
     hi StartifyFooter  ctermfg=240
     hi StartifyFooter  ctermfg=240

+ 1 - 3
syntax/startify.vim

@@ -27,9 +27,7 @@ syntax match StartifyFile    /.*/ contains=
 execute 'syntax match StartifySlash /\'. s:sep .'/'
 execute 'syntax match StartifySlash /\'. s:sep .'/'
 execute 'syntax match StartifyPath /\%9c.*\'. s:sep .'/ contains=StartifySlash,StartifyVar'
 execute 'syntax match StartifyPath /\%9c.*\'. s:sep .'/ contains=StartifySlash,StartifyVar'
 
 
-if exists('g:startify_custom_header')
-  execute 'syntax region StartifyHeader start=/\%1l/ end=/\%'. (len(g:startify_custom_header) + 2) .'l/'
-endif
+execute 'syntax region StartifyHeader start=/\%1l/ end=/\%'. (len(g:startify_header) + 2) .'l/'
 
 
 if exists('g:startify_custom_footer')
 if exists('g:startify_custom_footer')
   execute 'syntax region StartifyFooter start=/\%'. startify#get_lastline() .'l/ end=/*/'
   execute 'syntax region StartifyFooter start=/\%'. startify#get_lastline() .'l/ end=/*/'