Refactoring
This commit is contained in:
parent
bdb389ef61
commit
362001d03e
|
@ -111,71 +111,8 @@ function! startify#insane_in_the_membrane() abort
|
|||
|
||||
let b:startify.section_header_lines = []
|
||||
|
||||
if exists('g:startify_lists')
|
||||
let s:lists = deepcopy(g:startify_lists)
|
||||
elseif exists('g:startify_list_order')
|
||||
" Convert old g:startify_list_order format to newer g:startify_lists format.
|
||||
let s:lists = []
|
||||
for item in g:startify_list_order
|
||||
if type(item) == type([])
|
||||
let header = item
|
||||
else
|
||||
if exists('header')
|
||||
let s:lists += [{ 'type': item, 'header': header }]
|
||||
unlet header
|
||||
else
|
||||
let s:lists += [{ 'type': item }]
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
let s:lists = [
|
||||
\ { 'header': [s:padding_left .'MRU'], 'type': 'files' },
|
||||
\ { 'header': [s:padding_left .'MRU '. getcwd()], 'type': 'dir' },
|
||||
\ { 'header': [s:padding_left .'Sessions'], 'type': 'sessions' },
|
||||
\ { 'header': [s:padding_left .'Bookmarks'], 'type': 'bookmarks' },
|
||||
\ { 'header': [s:padding_left .'Commands'], 'type': 'commands' },
|
||||
\ ]
|
||||
endif
|
||||
|
||||
for list in s:lists
|
||||
if !has_key(list, 'type')
|
||||
continue
|
||||
endif
|
||||
|
||||
if type(list.type) == type('')
|
||||
if has_key(list, 'header')
|
||||
let s:last_message = list.header
|
||||
endif
|
||||
call s:show_{list.type}()
|
||||
elseif type(list.type) == type(function('tr'))
|
||||
try
|
||||
let entries = list.type()
|
||||
catch
|
||||
call s:warn(v:exception)
|
||||
continue
|
||||
endtry
|
||||
if empty(entries)
|
||||
unlet s:last_message
|
||||
continue
|
||||
endif
|
||||
|
||||
if has_key(list, 'header')
|
||||
let s:last_message = list.header
|
||||
call s:print_section_header()
|
||||
endif
|
||||
|
||||
for entry in entries
|
||||
let index = s:get_index_as_string(b:startify.entry_number)
|
||||
call append('$', s:padding_left .'['. index .']'. repeat(' ', (3 - strlen(index))) . entry.line)
|
||||
call s:register(line('$'), index, 'special', entry.cmd, '')
|
||||
let b:startify.entry_number += 1
|
||||
endfor
|
||||
call append('$', '')
|
||||
else
|
||||
call s:warn('Wrong format for g:startify_lists: '. string(list))
|
||||
endif
|
||||
endfor
|
||||
let s:lists = s:get_lists()
|
||||
call s:show_lists(s:lists)
|
||||
|
||||
silent $delete _
|
||||
|
||||
|
@ -486,6 +423,79 @@ function! startify#open_buffers(...) abort
|
|||
wincmd =
|
||||
endfunction
|
||||
|
||||
" Function: s:get_lists {{{1
|
||||
function! s:get_lists() abort
|
||||
if exists('g:startify_lists')
|
||||
return g:startify_lists
|
||||
elseif exists('g:startify_list_order')
|
||||
" Convert old g:startify_list_order format to newer g:startify_lists format.
|
||||
let lists = []
|
||||
for item in g:startify_list_order
|
||||
if type(item) == type([])
|
||||
let header = item
|
||||
else
|
||||
if exists('header')
|
||||
let lists += [{ 'type': item, 'header': header }]
|
||||
unlet header
|
||||
else
|
||||
let lists += [{ 'type': item }]
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
return lists
|
||||
else
|
||||
return [
|
||||
\ { 'header': [s:padding_left .'MRU'], 'type': 'files' },
|
||||
\ { 'header': [s:padding_left .'MRU '. getcwd()], 'type': 'dir' },
|
||||
\ { 'header': [s:padding_left .'Sessions'], 'type': 'sessions' },
|
||||
\ { 'header': [s:padding_left .'Bookmarks'], 'type': 'bookmarks' },
|
||||
\ { 'header': [s:padding_left .'Commands'], 'type': 'commands' },
|
||||
\ ]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Function: s:show_lists {{{1
|
||||
function! s:show_lists(lists) abort
|
||||
for list in a:lists
|
||||
if !has_key(list, 'type')
|
||||
continue
|
||||
endif
|
||||
|
||||
if type(list.type) == type('')
|
||||
if has_key(list, 'header')
|
||||
let s:last_message = list.header
|
||||
endif
|
||||
call s:show_{list.type}()
|
||||
elseif type(list.type) == type(function('tr'))
|
||||
try
|
||||
let entries = list.type()
|
||||
catch
|
||||
call s:warn(v:exception)
|
||||
continue
|
||||
endtry
|
||||
if empty(entries)
|
||||
unlet s:last_message
|
||||
continue
|
||||
endif
|
||||
|
||||
if has_key(list, 'header')
|
||||
let s:last_message = list.header
|
||||
call s:print_section_header()
|
||||
endif
|
||||
|
||||
for entry in entries
|
||||
let index = s:get_index_as_string(b:startify.entry_number)
|
||||
call append('$', s:padding_left .'['. index .']'. repeat(' ', (3 - strlen(index))) . entry.line)
|
||||
call s:register(line('$'), index, 'special', entry.cmd, '')
|
||||
let b:startify.entry_number += 1
|
||||
endfor
|
||||
call append('$', '')
|
||||
else
|
||||
call s:warn('Wrong format for g:startify_lists: '. string(list))
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Function: s:open_buffer {{{1
|
||||
function! s:open_buffer(entry)
|
||||
if a:entry.type == 'special'
|
||||
|
|
Loading…
Reference in a new issue