Skip to content

Commit 435786b

Browse files
committed
Define version as variable, include version in messages
1 parent 1f9c911 commit 435786b

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

autoload/xolox/session.vim

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
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

1614
function! 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
312310
endfunction
@@ -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
326324
endfunction
@@ -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

420418
function! 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
513511
function! 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
519517
endfunction
@@ -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

plugin/session.vim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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/
5-
" Version: 1.4.8
65

76
" Support for automatic update using the GLVS plug-in.
87
" GetLatestVimScripts: 3150 1 :AutoInstall: session.zip
@@ -12,6 +11,8 @@ if &cp || exists('g:loaded_session')
1211
finish
1312
endif
1413

14+
let g:session_version = '1.4.9'
15+
1516
" When you start Vim without opening any files the plug-in will prompt you
1617
" whether you want to load the default session. Other supported values for
1718
" this option are 'yes' (to load the default session without prompting) and
@@ -50,8 +51,8 @@ if !isdirectory(s:directory)
5051
call mkdir(s:directory, 'p')
5152
endif
5253
if filewritable(s:directory) != 2
53-
let s:msg = "session.vim: The sessions directory %s isn't writable!"
54-
call xolox#misc#msg#warn(s:msg, string(s:directory))
54+
let s:msg = "session.vim %s: The sessions directory %s isn't writable!"
55+
call xolox#misc#msg#warn(s:msg, g:session_version, string(s:directory))
5556
unlet s:msg
5657
finish
5758
endif

0 commit comments

Comments
 (0)