浏览代码

Merge branch 'pers-sessions'

Marco Hinz 11 年之前
父节点
当前提交
fc9a305bd9
共有 3 个文件被更改,包括 34 次插入9 次删除
  1. 28 6
      autoload/startify.vim
  2. 4 1
      doc/startify.txt
  3. 2 2
      plugin/startify.vim

+ 28 - 6
autoload/startify.vim

@@ -47,7 +47,7 @@ function! startify#get_lastline() abort
 endfunction
 
 " Function: #insane_in_the_membrane {{{1
-function! startify#insane_in_the_membrane() abort
+function! startify#insane_in_the_membrane(callingbuffer) abort
   if !empty(v:servername) && exists('g:startify_skiplist_server')
     for servname in g:startify_skiplist_server
       if servname == v:servername
@@ -56,10 +56,14 @@ function! startify#insane_in_the_membrane() abort
     endfor
   endif
 
+  if a:callingbuffer != 0
+    let s:callingbuffer = a:callingbuffer
+  endif
+
+  enew
+  set filetype=startify
   setlocal noswapfile nobuflisted buftype=nofile bufhidden=wipe
   setlocal nonumber nocursorline nocursorcolumn nolist statusline=\ startify
-  set filetype=startify
-
   if v:version >= 703
     setlocal norelativenumber
   endif
@@ -155,18 +159,23 @@ endfunction
 " Function: #session_load {{{1
 function! startify#session_load(...) abort
   if !isdirectory(s:session_dir)
-    echo 'The session directory does not exist: '. s:session_dir
+    echomsg 'The session directory does not exist: '. s:session_dir
     return
   elseif empty(startify#session_list_as_string(''))
-    echo 'There are no sessions...'
+    echomsg 'There are no sessions...'
     return
   endif
-  call startify#session_delete_buffers()
   let spath = s:session_dir . s:sep . (exists('a:1')
         \ ? a:1
         \ : input('Load this session: ', fnamemodify(v:this_session, ':t'), 'custom,startify#session_list_as_string'))
         \ | redraw
   if filereadable(spath)
+    if get(g:, 'startify_session_persistence')
+          \ && exists('v:this_session')
+          \ && filewritable(v:this_session)
+      call startify#session_write(fnameescape(v:this_session))
+    endif
+    call startify#session_delete_buffers()
     execute 'source '. fnameescape(spath)
   else
     echo 'No such file: '. spath
@@ -221,6 +230,19 @@ endfunction
 function! startify#session_write(spath)
   let ssop = &sessionoptions
   try
+    " if this function was called through :Startify instead of :SLoad
+    " switch back to the previous buffer before saving the session
+    if exists('s:callingbuffer')
+      redir => callingbuffer
+      file
+      redir END
+      if callingbuffer !~# '\[No Name\]'
+        execute 'buffer' s:callingbuffer
+      endif
+      unlet s:callingbuffer
+    endif
+    " prevent saving already deleted buffers that were in the arglist
+    silent! argdelete *
     set sessionoptions-=options
     execute 'mksession!' a:spath
   catch

+ 4 - 1
doc/startify.txt

@@ -213,7 +213,10 @@ Great way to create a portable project folder.
 >
     let g:startify_session_persistence = 0
 <
-Automatically update sessions before exiting Vim.
+Automatically update sessions in two cases:
+
+    1) Before leaving Vim
+    2) Before loading a new session via :SLoad
 
 This also works for sessions started with:
 >

+ 2 - 2
plugin/startify.vim

@@ -14,7 +14,7 @@ augroup startify
   if !get(g:, 'startify_disable_at_vimenter')
     autocmd VimEnter *
           \ if !argc() && (line2byte('$') == -1) && (v:progname =~? '^[gmnq]\=vim\=x\=\%[\.exe]$') |
-          \   call startify#insane_in_the_membrane() |
+          \   call startify#insane_in_the_membrane(0) |
           \ endif |
           \ autocmd! startify VimEnter
   endif
@@ -30,4 +30,4 @@ augroup END
 command! -nargs=? -bar -complete=customlist,startify#session_list SSave   call startify#session_save(<f-args>)
 command! -nargs=? -bar -complete=customlist,startify#session_list SLoad   call startify#session_load(<f-args>)
 command! -nargs=? -bar -complete=customlist,startify#session_list SDelete call startify#session_delete(<f-args>)
-command! -nargs=0 -bar Startify enew | call startify#insane_in_the_membrane()
+command! -nargs=0 -bar Startify call startify#insane_in_the_membrane(bufnr('%'))