Browse Source

Set StartifySection via syntax file

This keeps it highlighted after 'set ft=startify' etc.

References #117.
Daniel Hahler 11 years ago
parent
commit
07e10a15a0
2 changed files with 12 additions and 11 deletions
  1. 5 9
      autoload/startify.vim
  2. 7 2
      syntax/startify.vim

+ 5 - 9
autoload/startify.vim

@@ -33,7 +33,7 @@ let s:sep = startify#get_separator()
 
 " Function: #get_lastline {{{1
 function! startify#get_lastline() abort
-  return s:lastline
+  return s:lastline + 1
 endfunction
 
 " Function: #insane_in_the_membrane {{{1
@@ -51,7 +51,6 @@ function! startify#insane_in_the_membrane() abort
   endif
 
   enew
-  set filetype=startify
   setlocal
         \ bufhidden=wipe
         \ buftype=nofile
@@ -91,7 +90,7 @@ function! startify#insane_in_the_membrane() abort
     echohl None
   endif
 
-  let s:section_header_lines = []
+  let w:startify_section_header_lines = []
   let s:lists = get(g:, 'startify_list_order', [
         \ ['   Last recently opened files:'],
         \ 'files',
@@ -114,10 +113,6 @@ function! startify#insane_in_the_membrane() abort
 
   silent $delete _
 
-  for item in s:section_header_lines
-    execute 'syntax region StartifySection start=/\%'. item .'l/ end=/$/'
-  endfor
-
   if s:show_special
     call append('$', ['', '   [q]  <quit>'])
   endif
@@ -155,6 +150,7 @@ function! startify#insane_in_the_membrane() abort
   call cursor(s:firstline + (s:show_special ? 2 : 0), 5)
 
   autocmd startify CursorMoved <buffer> call s:set_cursor()
+  set filetype=startify
   silent! doautocmd <nomodeline> User Startified
 endfunction
 
@@ -492,7 +488,7 @@ function! s:set_cursor() abort
   let movement = 2 * (s:newline > s:oldline) - 1
 
   " skip section headers lines until an entry is found
-  while index(s:section_header_lines, s:newline) != -1
+  while index(w:startify_section_header_lines, s:newline) != -1
     let s:newline += movement
   endwhile
 
@@ -650,7 +646,7 @@ function! s:print_section_header() abort
   let curline = line('.')
 
   for lnum in range(curline, curline + len(s:last_message) + 1)
-    call add(s:section_header_lines, lnum)
+    call add(w:startify_section_header_lines, lnum)
   endfor
 
   call append('$', s:last_message + [''])

+ 7 - 2
syntax/startify.vim

@@ -32,8 +32,13 @@ if exists('g:startify_custom_header')
 endif
 
 if exists('g:startify_custom_footer')
-  autocmd startify User Startified
-        \ execute 'syntax region StartifyFooter start=/\%'. (startify#get_lastline() + 1) .'l/ end=/*/'
+  execute 'syntax region StartifyFooter start=/\%'. startify#get_lastline() .'l/ end=/*/'
+endif
+
+if exists('w:startify_section_header_lines')
+  for line in w:startify_section_header_lines
+    execute 'syntax region StartifySection start=/\%'. line .'l/ end=/$/'
+  endfor
 endif
 
 highlight default link StartifyBracket Delimiter