1
1
" Vim script
2
2
" Author: Peter Odding
3
- " Last Change: June 13 , 2011
3
+ " Last Change: June 18 , 2011
4
4
" URL: http://peterodding.com/code/vim/session/
5
5
6
- let s: script = expand (' <sfile>:p:~' )
7
-
8
6
" Public API for session persistence. {{{1
9
7
10
8
" The functions in this fold take a single list argument in which the Vim
@@ -15,7 +13,7 @@ let s:script = expand('<sfile>:p:~')
15
13
16
14
function ! xolox#session#save_session (commands, filename) " {{{2
17
15
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.' ))
19
17
call add (a: commands , ' " Open this file in Vim and run :source % to restore your session.' )
20
18
call add (a: commands , ' ' )
21
19
call add (a: commands , ' set guioptions=' . escape (&go , ' "\' ))
@@ -295,8 +293,8 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
295
293
let starttime = xolox#misc#timer#start ()
296
294
let path = xolox#session#name_to_path (name)
297
295
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 , ' :~' ))
300
298
elseif a: bang == ' !' || ! s: session_is_locked (path , ' OpenSession' )
301
299
let oldcwd = s: nerdtree_persist ()
302
300
call xolox#session#close_cmd (a: bang , 1 )
@@ -305,8 +303,8 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
305
303
execute ' source' fnameescape (path )
306
304
unlet ! s: session_is_dirty
307
305
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 , ' :~' ))
310
308
endif
311
309
endif
312
310
endfunction
@@ -316,11 +314,11 @@ function! xolox#session#view_cmd(name) abort " {{{2
316
314
if name != ' '
317
315
let path = xolox#session#name_to_path (name)
318
316
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 , ' :~' ))
321
319
else
322
320
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 , ' :~' ))
324
322
endif
325
323
endif
326
324
endfunction
@@ -337,12 +335,12 @@ function! xolox#session#save_cmd(name, bang) abort " {{{2
337
335
call map (lines , ' v:val . "\r"' )
338
336
endif
339
337
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)
342
340
else
343
341
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)
346
344
let v: this_session = path
347
345
call s: lock_session (path )
348
346
unlet ! s: session_is_dirty
@@ -355,16 +353,16 @@ function! xolox#session#delete_cmd(name, bang) " {{{2
355
353
if name != ' '
356
354
let path = xolox#session#name_to_path (name)
357
355
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 , ' :~' ))
360
358
elseif a: bang == ' !' || ! s: session_is_locked (path , ' DeleteSession' )
361
359
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 , ' :~' ))
364
362
else
365
363
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 , ' :~' ))
368
366
endif
369
367
endif
370
368
endif
@@ -404,13 +402,13 @@ function! xolox#session#close_cmd(bang, silent) abort " {{{2
404
402
unlet ! s: session_is_dirty
405
403
if v: this_session == ' '
406
404
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 )
409
407
endif
410
408
else
411
409
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 , ' :~' ))
414
412
endif
415
413
let v: this_session = ' '
416
414
endif
@@ -419,8 +417,8 @@ endfunction
419
417
420
418
function ! xolox#session#restart_cmd (bang , args ) abort " {{{2
421
419
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 )
424
422
else
425
423
let name = s: get_name (' ' , 0 )
426
424
if name == ' ' | let name = ' restart' | endif
@@ -513,7 +511,7 @@ endfunction
513
511
function ! s: last_session_persist (name)
514
512
if g: session_default_to_last
515
513
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 )
517
515
endif
518
516
endif
519
517
endfunction
@@ -561,9 +559,9 @@ function! s:session_is_locked(session_path, ...)
561
559
let lines = readfile (lock_file)
562
560
if lines [0 ] !=? v: servername
563
561
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."
565
563
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 )
567
565
endif
568
566
return 1
569
567
endif
0 commit comments