1 " Vim script
 2 " Author: Peter Odding
 3 " Last Change: August 30, 2010
 4 " URL: http://peterodding.com/code/vim/session/
 5 " Version: 1.3
 6 
 7 " Support for automatic update using the GLVS plug-in.
 8 " GetLatestVimScripts: 3150 1 :AutoInstall: session.zip
 9 
10 " Don't load the plug-in when &compatible is set or it was already loaded.
11 if &cp || exists('g:loaded_session')
12   finish
13 endif
14 
15 " Automatic loading of the default session is disabled by default.
16 if !exists('g:session_autoload')
17   let g:session_autoload = 0
18 endif
19 
20 " Automatic saving of the default session is disabled by default.
21 if !exists('g:session_autosave')
22   let g:session_autosave = 0
23 endif
24 
25 " The default directory where session scripts are stored.
26 if !exists('g:session_directory')
27   if has('win32') || has('win64')
28     let g:session_directory = '~\vimfiles\sessions'
29   else
30     let g:session_directory = '~/.vim/sessions'
31   endif
32 endif
33 
34 " Make sure the session scripts directory exists and is writable.
35 let s:directory = fnamemodify(g:session_directory, ':p')
36 if !isdirectory(s:directory)
37   call mkdir(s:directory, 'p')
38 endif
39 if filewritable(s:directory) != 2
40   let s:msg = "session.vim: The sessions directory %s isn't writable!"
41   call xolox#warning(s:msg, string(s:directory))
42   unlet s:msg
43   finish
44 endif
45 unlet s:directory
46 
47 " Define automatic commands for automatic session management.
48 augroup PluginSession
49   autocmd!
50   au VimEnter * nested call session#auto_load()
51   au VimLeavePre * call session#auto_save()
52   au VimLeavePre * call session#auto_unlock()
53   au TabEnter,WinEnter * call session#auto_dirty_check()
54 augroup END
55 
56 " Define commands that enable users to manage multiple named sessions.
57 command! -bar -bang -nargs=? -complete=customlist,session#complete_names OpenSession call session#open_cmd(<q-args>, <q-bang>)
58 command! -bar -nargs=? -complete=customlist,session#complete_names ViewSession call session#view_cmd(<q-args>)
59 command! -bar -bang -nargs=? -complete=customlist,session#complete_names SaveSession call session#save_cmd(<q-args>, <q-bang>)
60 command! -bar -bang -nargs=? -complete=customlist,session#complete_names DeleteSession call session#delete_cmd(<q-args>, <q-bang>)
61 command! -bar -bang CloseSession call session#close_cmd(<q-bang>, 0)
62 command! -bar -bang RestartVim call session#restart_cmd(<q-bang>)
63 
64 " Don't reload the plug-in once it has loaded successfully.
65 let g:loaded_session = 1
66 
67 " vim: ts=2 sw=2 et