ソースを参照

Make g:startify_commands more flexible

Marco Hinz 9 年 前
コミット
e5ce53fbef
2 ファイル変更34 行追加46 行削除
  1. 15 12
      autoload/startify.vim
  2. 19 34
      doc/startify.txt

+ 15 - 12
autoload/startify.vim

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

+ 19 - 34
doc/startify.txt

@@ -36,8 +36,8 @@ CONTENTS                                                     *startify-contents*
 ==============================================================================
 INTRO                                                           *startify-intro*
 
-Startify is a plugin that shows recently used files, bookmarks, ex commands
-and sessions that were saved to a certain directory.
+Startify is a plugin that shows recently used files, bookmarks, commands and
+sessions that were saved to a certain directory.
 
 ==============================================================================
 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
    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.
 
    You can either navigate to a certain menu entry and hit enter or you just
@@ -87,7 +87,6 @@ default values.
 
     Most used options:~
     |g:startify_bookmarks|
-    |g:startify_ex_commands|
     |g:startify_change_to_dir|
     |g:startify_change_to_vcs_root|
     |g:startify_custom_header|
@@ -98,6 +97,7 @@ default values.
     |g:startify_update_oldfiles|
 
     Misc options:~
+    |g:startify_commands|
     |g:startify_custom_footer|
     |g:startify_custom_header_quotes|
     |g:startify_custom_indices|
@@ -130,7 +130,7 @@ The default for Windows systems is '$HOME\vimfiles\session'.
                                                          *g:startify_list_order*
 >
     let g:startify_list_order = ['files', 'dir', 'bookmarks', 'sessions',
-        \ 'ex_commands']
+        \ 'commands']
 <
 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|.
 
-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:~
 
@@ -180,8 +180,8 @@ Section headers example:~
             \ 'sessions',
             \ ['   These are my bookmarks:'],
             \ 'bookmarks',
-            \ ['   These are my ex commands:'],
-            \ 'ex_commands',
+            \ ['   These are my commands:'],
+            \ 'commands',
             \ ]
 <
 Feel free to add some cool ASCII action!
@@ -202,18 +202,21 @@ Example:
 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
-list can contain two kinds of types. Either an ex command or a dictionary
-whereas the key is the custom index and the value the ex command.
+A list of commands to execute on selection. Leading colons are optional. It
+supports optional custom indices and/or command descriptions.
 
 Example:
 >
-    let g:startify_ex_commands = [ {'s': 'enew | set ft=sql'},
-        \ 'colorscheme bclear' ]
+    let g:startify_commands = [
+        \ ':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.
 
@@ -904,19 +907,6 @@ This is my configuration..
     let g:startify_session_persistence    = 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 = [
                 \ 'COMMIT_EDITMSG',
                 \ 'bundle/.*/doc',
@@ -929,11 +919,6 @@ This is my configuration..
                 \ '~/golfing',
                 \ ]
 
-    let g:startify_ex_commands = [
-                \ { 's': 'enew | set ft=sql' },
-                \ 'colorscheme bclear',
-                \ ]
-
     let g:startify_custom_footer =
           \ ['', "   Vim is charityware. Please read ':help uganda'.", '']