add input dialog completion

This commit is contained in:
Marco Hinz 2013-04-24 15:01:43 +02:00
parent 6cfbbbd6a1
commit 90bfd61296
3 changed files with 20 additions and 11 deletions

View file

@ -8,8 +8,19 @@ if exists('g:autoloaded_startify') || &cp
endif
let g:autoloaded_startify = 1
function! startify#get_session_names(lead, ...) abort
return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
endfunction
function! startify#get_session_names_as_string(lead, ...) abort
return join(map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")'), "\n")
endfunction
function! startify#save_session(...) abort
let spath = g:startify_session_dir .'/'. (exists('a:1') ? a:1 : input('Save under this session name: ')) | redraw
let spath = g:startify_session_dir .'/'. (exists('a:1')
\ ? a:1
\ : input('Save under this session name: ', '', 'custom,startify#get_session_names_as_string'))
\ | redraw
if !filereadable(spath)
execute 'mksession '. spath | echo 'Session saved under: '. spath
return
@ -23,7 +34,10 @@ function! startify#save_session(...) abort
endfunction
function! startify#load_session(...) abort
let spath = g:startify_session_dir .'/'. (exists('a:1') ? a:1 : input('Load this session: ')) | redraw
let spath = g:startify_session_dir .'/'. (exists('a:1')
\ ? a:1
\ : input('Load this session: ', '', 'custom,startify#get_session_names_as_string'))
\ | redraw
if filereadable(spath)
execute 'source '. spath
else

View file

@ -109,8 +109,8 @@ There are only two commands for handling sessions:
These take either 0 or 1 argument. If you don't specify the session name as an
argument, they will just ask for it.
You can use <c-u> and <tab> for argument completion. Providing only a part of
the session name works, too.
Providing only a part of the session name works too, if you complete the
argument with either <c-u> or <tab> afterwards.
==============================================================================

View file

@ -20,13 +20,8 @@ augroup startify
\endif
augroup END
command! -nargs=? -bar -complete=customlist,s:get_session_names SSave call startify#save_session(<f-args>)
command! -nargs=? -bar -complete=customlist,s:get_session_names SLoad call startify#load_session(<f-args>)
" Function: s:get_session_names {{{1
function! s:get_session_names(lead, ...) abort
return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
endfunction
command! -nargs=? -bar -complete=customlist,startify#get_session_names SSave call startify#save_session(<f-args>)
command! -nargs=? -bar -complete=customlist,startify#get_session_names SLoad call startify#load_session(<f-args>)
" Function: s:start {{{1
function! s:start() abort