From 90bfd612968cab09fca48c3d951719875e89639a Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 24 Apr 2013 15:01:43 +0200 Subject: [PATCH] add input dialog completion --- autoload/startify.vim | 18 ++++++++++++++++-- doc/startify.txt | 4 ++-- plugin/startify.vim | 9 ++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/autoload/startify.vim b/autoload/startify.vim index 212bb67..d2ae1ba 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -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 diff --git a/doc/startify.txt b/doc/startify.txt index e07d178..a844f30 100644 --- a/doc/startify.txt +++ b/doc/startify.txt @@ -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 and 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 or afterwards. ============================================================================== diff --git a/plugin/startify.vim b/plugin/startify.vim index cbaf52b..ecba660 100644 --- a/plugin/startify.vim +++ b/plugin/startify.vim @@ -20,13 +20,8 @@ augroup startify \endif augroup END -command! -nargs=? -bar -complete=customlist,s:get_session_names SSave call startify#save_session() -command! -nargs=? -bar -complete=customlist,s:get_session_names SLoad call startify#load_session() - -" 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() +command! -nargs=? -bar -complete=customlist,startify#get_session_names SLoad call startify#load_session() " Function: s:start {{{1 function! s:start() abort