Make g:startify_commands more flexible

This commit is contained in:
Marco Hinz 2016-05-31 23:32:51 +02:00
parent e551be9cb0
commit e5ce53fbef
2 changed files with 34 additions and 46 deletions

View file

@ -113,7 +113,7 @@ function! startify#insane_in_the_membrane() abort
\ [' MRU '. getcwd()], 'dir', \ [' MRU '. getcwd()], 'dir',
\ [' Sessions'], 'sessions', \ [' Sessions'], 'sessions',
\ [' Bookmarks'], 'bookmarks', \ [' Bookmarks'], 'bookmarks',
\ [' Ex commands'], 'ex_commands', \ [' Commands'], 'commands',
\ ]) \ ])
for item in s:lists for item in s:lists
@ -622,9 +622,9 @@ function! s:show_bookmarks() abort
call append('$', '') call append('$', '')
endfunction endfunction
" Function: s:show_ex_commands {{{1 " Function: s:show_commands {{{1
function! s:show_ex_commands() abort function! s:show_commands() abort
if !exists('g:startify_ex_commands') || empty(g:startify_ex_commands) if !exists('g:startify_commands') || empty(g:startify_commands)
return return
endif endif
@ -632,18 +632,21 @@ function! s:show_ex_commands() abort
call s:print_section_header() call s:print_section_header()
endif endif
for ex_command_item in g:startify_ex_commands for entry in g:startify_commands
if type(ex_command_item) == type({}) if type(entry) == type({}) " with custom index
let [index, ex_command_str] = items(ex_command_item)[0] let [index, command] = items(entry)[0]
else " string else
let [index, ex_command_str] = [s:get_index_as_string(s:entry_number), ex_command_item] let command = entry
let index = s:get_index_as_string(s:entry_number)
let s:entry_number += 1 let s:entry_number += 1
endif endif
" If no list is given, the description is the command itself.
let [desc, cmd] = type(command) == type([]) ? command : [command, command]
call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . ex_command_str) call append('$', ' ['. index .']'. repeat(' ', (3 - strlen(index))) . desc)
call s:register(line('$'), index, 'special', ex_command_str, '', s:nowait_string) call s:register(line('$'), index, 'special', cmd, '', s:nowait_string)
unlet ex_command_item " avoid type mismatch for heterogeneous lists unlet entry command
endfor endfor
call append('$', '') call append('$', '')

View file

@ -36,8 +36,8 @@ CONTENTS *startify-contents*
============================================================================== ==============================================================================
INTRO *startify-intro* INTRO *startify-intro*
Startify is a plugin that shows recently used files, bookmarks, ex commands Startify is a plugin that shows recently used files, bookmarks, commands and
and sessions that were saved to a certain directory. sessions that were saved to a certain directory.
============================================================================== ==============================================================================
USAGE *startify-usage* USAGE *startify-usage*
@ -48,7 +48,7 @@ Startify basically provides two things:
it reads from STDIN), startify will show a small but pretty start screen it reads from STDIN), startify will show a small but pretty start screen
that shows recently used files (using viminfo) and sessions by default. that shows recently used files (using viminfo) and sessions by default.
Additionally, you can define bookmarks (thus entries for files) and ex Additionally, you can define bookmarks (thus entries for files) and
commands that always should be available on the start screen. commands that always should be available on the start screen.
You can either navigate to a certain menu entry and hit enter or you just You can either navigate to a certain menu entry and hit enter or you just
@ -87,7 +87,6 @@ default values.
Most used options:~ Most used options:~
|g:startify_bookmarks| |g:startify_bookmarks|
|g:startify_ex_commands|
|g:startify_change_to_dir| |g:startify_change_to_dir|
|g:startify_change_to_vcs_root| |g:startify_change_to_vcs_root|
|g:startify_custom_header| |g:startify_custom_header|
@ -98,6 +97,7 @@ default values.
|g:startify_update_oldfiles| |g:startify_update_oldfiles|
Misc options:~ Misc options:~
|g:startify_commands|
|g:startify_custom_footer| |g:startify_custom_footer|
|g:startify_custom_header_quotes| |g:startify_custom_header_quotes|
|g:startify_custom_indices| |g:startify_custom_indices|
@ -130,7 +130,7 @@ The default for Windows systems is '$HOME\vimfiles\session'.
*g:startify_list_order* *g:startify_list_order*
> >
let g:startify_list_order = ['files', 'dir', 'bookmarks', 'sessions', let g:startify_list_order = ['files', 'dir', 'bookmarks', 'sessions',
\ 'ex_commands'] \ 'commands']
< <
At the moment startify supports these lists:~ At the moment startify supports these lists:~
@ -153,9 +153,9 @@ At the moment startify supports these lists:~
This lists all the sessions saved in the directory |g:startify_session_dir|. This lists all the sessions saved in the directory |g:startify_session_dir|.
5) "ex_commands" 5) "commands"
This lists ex commands defined in |g:startify_ex_commands|. This lists commands defined in |g:startify_commands|.
Section headers:~ Section headers:~
@ -180,8 +180,8 @@ Section headers example:~
\ 'sessions', \ 'sessions',
\ [' These are my bookmarks:'], \ [' These are my bookmarks:'],
\ 'bookmarks', \ 'bookmarks',
\ [' These are my ex commands:'], \ [' These are my commands:'],
\ 'ex_commands', \ 'commands',
\ ] \ ]
< <
Feel free to add some cool ASCII action! Feel free to add some cool ASCII action!
@ -202,18 +202,21 @@ Example:
NOTE: Avoid using keys from |startify-mappings| if providing custom indices. NOTE: Avoid using keys from |startify-mappings| if providing custom indices.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*g:startify_ex_commands* *g:startify_commands*
> >
let g:startify_ex_commands = [] let g:startify_commands = []
< <
A list of ex commands (without the colon) to display on the start screen. The A list of commands to execute on selection. Leading colons are optional. It
list can contain two kinds of types. Either an ex command or a dictionary supports optional custom indices and/or command descriptions.
whereas the key is the custom index and the value the ex command.
Example: Example:
> >
let g:startify_ex_commands = [ {'s': 'enew | set ft=sql'}, let g:startify_commands = [
\ 'colorscheme bclear' ] \ ':help reference',
\ ['Vim Reference', 'h ref'],
\ {'h': 'h ref'},
\ {'m': ['My magical function', 'call Magic()']},
\ ]
< <
NOTE: Avoid using keys from |startify-mappings| if providing custom indices. NOTE: Avoid using keys from |startify-mappings| if providing custom indices.
@ -904,19 +907,6 @@ This is my configuration..
let g:startify_session_persistence = 1 let g:startify_session_persistence = 1
let g:startify_session_delete_buffers = 1 let g:startify_session_delete_buffers = 1
let g:startify_list_order = [
\ [' LRU:'],
\ 'files',
\ [' LRU within this dir:'],
\ 'dir',
\ [' Sessions:'],
\ 'sessions',
\ [' Bookmarks:'],
\ 'bookmarks',
\ [' Ex commands:'],
\ 'ex_commands',
\ ]
let g:startify_skiplist = [ let g:startify_skiplist = [
\ 'COMMIT_EDITMSG', \ 'COMMIT_EDITMSG',
\ 'bundle/.*/doc', \ 'bundle/.*/doc',
@ -929,11 +919,6 @@ This is my configuration..
\ '~/golfing', \ '~/golfing',
\ ] \ ]
let g:startify_ex_commands = [
\ { 's': 'enew | set ft=sql' },
\ 'colorscheme bclear',
\ ]
let g:startify_custom_footer = let g:startify_custom_footer =
\ ['', " Vim is charityware. Please read ':help uganda'.", ''] \ ['', " Vim is charityware. Please read ':help uganda'.", '']