11" Vim script
22" Author: Peter Odding
3- " Last Change: June 13 , 2011
3+ " Last Change: June 18 , 2011
44" URL: http://peterodding.com/code/vim/session/
55
6- let s: script = expand (' <sfile>:p:~' )
7-
86" Public API for session persistence. {{{1
97
108" The functions in this fold take a single list argument in which the Vim
@@ -15,7 +13,7 @@ let s:script = expand('<sfile>:p:~')
1513
1614function ! xolox#session#save_session (commands, filename) " {{{2
1715 call add (a: commands , ' " ' . a: filename . ' : Vim session script.' )
18- call add (a: commands , ' " Created by ' . s: script . ' on ' . strftime (' %d %B %Y at %H:%M:%S.' ))
16+ call add (a: commands , ' " Created by session.vim ' . g: session_version . ' on ' . strftime (' %d %B %Y at %H:%M:%S.' ))
1917 call add (a: commands , ' " Open this file in Vim and run :source % to restore your session.' )
2018 call add (a: commands , ' ' )
2119 call add (a: commands , ' set guioptions=' . escape (&go , ' "\' ))
@@ -295,8 +293,8 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
295293 let starttime = xolox#misc#timer#start ()
296294 let path = xolox#session#name_to_path (name)
297295 if ! filereadable (path )
298- let msg = " %s: The %s session at %s doesn't exist!"
299- call xolox#misc#msg#warn (msg, s: script , string (name), fnamemodify (path , ' :~' ))
296+ let msg = " session.vim %s: The %s session at %s doesn't exist!"
297+ call xolox#misc#msg#warn (msg, g: session_version , string (name), fnamemodify (path , ' :~' ))
300298 elseif a: bang == ' !' || ! s: session_is_locked (path , ' OpenSession' )
301299 let oldcwd = s: nerdtree_persist ()
302300 call xolox#session#close_cmd (a: bang , 1 )
@@ -305,8 +303,8 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
305303 execute ' source' fnameescape (path )
306304 unlet ! s: session_is_dirty
307305 call s: last_session_persist (name)
308- call xolox#misc#timer#stop (" %s: Opened %s session in %s." , s: script , string (name), starttime)
309- call xolox#misc#msg#info (" %s: Opened %s session from %s." , s: script , string (name), fnamemodify (path , ' :~' ))
306+ call xolox#misc#timer#stop (" session.vim %s: Opened %s session in %s." , g: session_version , string (name), starttime)
307+ call xolox#misc#msg#info (" session.vim %s: Opened %s session from %s." , g: session_version , string (name), fnamemodify (path , ' :~' ))
310308 endif
311309 endif
312310endfunction
@@ -316,11 +314,11 @@ function! xolox#session#view_cmd(name) abort " {{{2
316314 if name != ' '
317315 let path = xolox#session#name_to_path (name)
318316 if ! filereadable (path )
319- let msg = " %s: The %s session at %s doesn't exist!"
320- call xolox#misc#msg#warn (msg, s: script , string (name), fnamemodify (path , ' :~' ))
317+ let msg = " session.vim %s: The %s session at %s doesn't exist!"
318+ call xolox#misc#msg#warn (msg, g: session_version , string (name), fnamemodify (path , ' :~' ))
321319 else
322320 execute ' tab drop' fnameescape (path )
323- call xolox#misc#msg#info (" %s: Viewing session script %s." , s: script , fnamemodify (path , ' :~' ))
321+ call xolox#misc#msg#info (" session.vim %s: Viewing session script %s." , g: session_version , fnamemodify (path , ' :~' ))
324322 endif
325323 endif
326324endfunction
@@ -337,12 +335,12 @@ function! xolox#session#save_cmd(name, bang) abort " {{{2
337335 call map (lines , ' v:val . "\r"' )
338336 endif
339337 if writefile (lines , path ) != 0
340- let msg = " %s: Failed to save %s session to %s!"
341- call xolox#misc#msg#warn (msg, s: script , string (name), friendly_path)
338+ let msg = " session.vim %s: Failed to save %s session to %s!"
339+ call xolox#misc#msg#warn (msg, g: session_version , string (name), friendly_path)
342340 else
343341 call s: last_session_persist (name)
344- call xolox#misc#timer#stop (" %s: Saved %s session in %s." , s: script , string (name), starttime)
345- call xolox#misc#msg#info (" %s: Saved %s session to %s." , s: script , string (name), friendly_path)
342+ call xolox#misc#timer#stop (" session.vim %s: Saved %s session in %s." , g: session_version , string (name), starttime)
343+ call xolox#misc#msg#info (" session.vim %s: Saved %s session to %s." , g: session_version , string (name), friendly_path)
346344 let v: this_session = path
347345 call s: lock_session (path )
348346 unlet ! s: session_is_dirty
@@ -355,16 +353,16 @@ function! xolox#session#delete_cmd(name, bang) " {{{2
355353 if name != ' '
356354 let path = xolox#session#name_to_path (name)
357355 if ! filereadable (path )
358- let msg = " %s: The %s session at %s doesn't exist!"
359- call xolox#misc#msg#warn (msg, s: script , string (name), fnamemodify (path , ' :~' ))
356+ let msg = " session.vim %s: The %s session at %s doesn't exist!"
357+ call xolox#misc#msg#warn (msg, g: session_version , string (name), fnamemodify (path , ' :~' ))
360358 elseif a: bang == ' !' || ! s: session_is_locked (path , ' DeleteSession' )
361359 if delete (path ) != 0
362- let msg = " %s: Failed to delete %s session at %s!"
363- call xolox#misc#msg#warn (msg, s: script , string (name), fnamemodify (path , ' :~' ))
360+ let msg = " session.vim %s: Failed to delete %s session at %s!"
361+ call xolox#misc#msg#warn (msg, g: session_version , string (name), fnamemodify (path , ' :~' ))
364362 else
365363 call s: unlock_session (path )
366- let msg = " %s: Deleted %s session at %s."
367- call xolox#misc#msg#info (msg, s: script , string (name), fnamemodify (path , ' :~' ))
364+ let msg = " session.vim %s: Deleted %s session at %s."
365+ call xolox#misc#msg#info (msg, g: session_version , string (name), fnamemodify (path , ' :~' ))
368366 endif
369367 endif
370368 endif
@@ -404,13 +402,13 @@ function! xolox#session#close_cmd(bang, silent) abort " {{{2
404402 unlet ! s: session_is_dirty
405403 if v: this_session == ' '
406404 if ! a: silent
407- let msg = " %s: Closed session."
408- call xolox#misc#msg#info (msg, s: script )
405+ let msg = " session.vim %s: Closed session."
406+ call xolox#misc#msg#info (msg, g: session_version )
409407 endif
410408 else
411409 if ! a: silent
412- let msg = " %s: Closed session %s."
413- call xolox#misc#msg#info (msg, s: script , fnamemodify (v: this_session , ' :~' ))
410+ let msg = " session.vim %s: Closed session %s."
411+ call xolox#misc#msg#info (msg, g: session_version , fnamemodify (v: this_session , ' :~' ))
414412 endif
415413 let v: this_session = ' '
416414 endif
@@ -419,8 +417,8 @@ endfunction
419417
420418function ! xolox#session#restart_cmd (bang , args ) abort " {{{2
421419 if ! has (' gui_running' )
422- let msg = " %s: The :RestartVim command only works in graphical Vim!"
423- call xolox#misc#msg#warn (msg, s: script )
420+ let msg = " session.vim %s: The :RestartVim command only works in graphical Vim!"
421+ call xolox#misc#msg#warn (msg, g: session_version )
424422 else
425423 let name = s: get_name (' ' , 0 )
426424 if name == ' ' | let name = ' restart' | endif
@@ -513,7 +511,7 @@ endfunction
513511function ! s: last_session_persist (name)
514512 if g: session_default_to_last
515513 if writefile ([a: name ], s: last_session_file ()) != 0
516- call xolox#misc#msg#warn (" Failed to persist name of last used session!" )
514+ call xolox#misc#msg#warn (" session.vim %s: Failed to persist name of last used session!" , g: session_version )
517515 endif
518516 endif
519517endfunction
@@ -561,9 +559,9 @@ function! s:session_is_locked(session_path, ...)
561559 let lines = readfile (lock_file)
562560 if lines [0 ] !=? v: servername
563561 if a: 0 >= 1
564- let msg = " %s: The %s session is locked by another Vim instance named %s! Use :%s! to override."
562+ let msg = " session.vim %s: The %s session is locked by another Vim instance named %s! Use :%s! to override."
565563 let name = string (fnamemodify (a: session_path , ' :t:r' ))
566- call xolox#misc#msg#warn (msg, s: script , name, string (lines [0 ]), a: 1 )
564+ call xolox#misc#msg#warn (msg, g: session_version , name, string (lines [0 ]), a: 1 )
567565 endif
568566 return 1
569567 endif
0 commit comments