From 435786b97cdb12cf76b71e537905339eb09f88cd Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sat, 18 Jun 2011 03:32:29 +0200 Subject: [PATCH] Define version as variable, include version in messages --- autoload/xolox/session.vim | 58 ++++++++++++++++++-------------------- plugin/session.vim | 9 +++--- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/autoload/xolox/session.vim b/autoload/xolox/session.vim index 86af127..494e850 100644 --- a/autoload/xolox/session.vim +++ b/autoload/xolox/session.vim @@ -1,10 +1,8 @@ " Vim script " Author: Peter Odding -" Last Change: June 13, 2011 +" Last Change: June 18, 2011 " URL: http://peterodding.com/code/vim/session/ -let s:script = expand(':p:~') - " Public API for session persistence. {{{1 " The functions in this fold take a single list argument in which the Vim @@ -15,7 +13,7 @@ let s:script = expand(':p:~') function! xolox#session#save_session(commands, filename) " {{{2 call add(a:commands, '" ' . a:filename . ': Vim session script.') - call add(a:commands, '" Created by ' . s:script . ' on ' . strftime('%d %B %Y at %H:%M:%S.')) + call add(a:commands, '" Created by session.vim ' . g:session_version . ' on ' . strftime('%d %B %Y at %H:%M:%S.')) call add(a:commands, '" Open this file in Vim and run :source % to restore your session.') call add(a:commands, '') call add(a:commands, 'set guioptions=' . escape(&go, ' "\')) @@ -295,8 +293,8 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2 let starttime = xolox#misc#timer#start() let path = xolox#session#name_to_path(name) if !filereadable(path) - let msg = "%s: The %s session at %s doesn't exist!" - call xolox#misc#msg#warn(msg, s:script, string(name), fnamemodify(path, ':~')) + let msg = "session.vim %s: The %s session at %s doesn't exist!" + call xolox#misc#msg#warn(msg, g:session_version, string(name), fnamemodify(path, ':~')) elseif a:bang == '!' || !s:session_is_locked(path, 'OpenSession') let oldcwd = s:nerdtree_persist() call xolox#session#close_cmd(a:bang, 1) @@ -305,8 +303,8 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2 execute 'source' fnameescape(path) unlet! s:session_is_dirty call s:last_session_persist(name) - call xolox#misc#timer#stop("%s: Opened %s session in %s.", s:script, string(name), starttime) - call xolox#misc#msg#info("%s: Opened %s session from %s.", s:script, string(name), fnamemodify(path, ':~')) + call xolox#misc#timer#stop("session.vim %s: Opened %s session in %s.", g:session_version, string(name), starttime) + call xolox#misc#msg#info("session.vim %s: Opened %s session from %s.", g:session_version, string(name), fnamemodify(path, ':~')) endif endif endfunction @@ -316,11 +314,11 @@ function! xolox#session#view_cmd(name) abort " {{{2 if name != '' let path = xolox#session#name_to_path(name) if !filereadable(path) - let msg = "%s: The %s session at %s doesn't exist!" - call xolox#misc#msg#warn(msg, s:script, string(name), fnamemodify(path, ':~')) + let msg = "session.vim %s: The %s session at %s doesn't exist!" + call xolox#misc#msg#warn(msg, g:session_version, string(name), fnamemodify(path, ':~')) else execute 'tab drop' fnameescape(path) - call xolox#misc#msg#info("%s: Viewing session script %s.", s:script, fnamemodify(path, ':~')) + call xolox#misc#msg#info("session.vim %s: Viewing session script %s.", g:session_version, fnamemodify(path, ':~')) endif endif endfunction @@ -337,12 +335,12 @@ function! xolox#session#save_cmd(name, bang) abort " {{{2 call map(lines, 'v:val . "\r"') endif if writefile(lines, path) != 0 - let msg = "%s: Failed to save %s session to %s!" - call xolox#misc#msg#warn(msg, s:script, string(name), friendly_path) + let msg = "session.vim %s: Failed to save %s session to %s!" + call xolox#misc#msg#warn(msg, g:session_version, string(name), friendly_path) else call s:last_session_persist(name) - call xolox#misc#timer#stop("%s: Saved %s session in %s.", s:script, string(name), starttime) - call xolox#misc#msg#info("%s: Saved %s session to %s.", s:script, string(name), friendly_path) + call xolox#misc#timer#stop("session.vim %s: Saved %s session in %s.", g:session_version, string(name), starttime) + call xolox#misc#msg#info("session.vim %s: Saved %s session to %s.", g:session_version, string(name), friendly_path) let v:this_session = path call s:lock_session(path) unlet! s:session_is_dirty @@ -355,16 +353,16 @@ function! xolox#session#delete_cmd(name, bang) " {{{2 if name != '' let path = xolox#session#name_to_path(name) if !filereadable(path) - let msg = "%s: The %s session at %s doesn't exist!" - call xolox#misc#msg#warn(msg, s:script, string(name), fnamemodify(path, ':~')) + let msg = "session.vim %s: The %s session at %s doesn't exist!" + call xolox#misc#msg#warn(msg, g:session_version, string(name), fnamemodify(path, ':~')) elseif a:bang == '!' || !s:session_is_locked(path, 'DeleteSession') if delete(path) != 0 - let msg = "%s: Failed to delete %s session at %s!" - call xolox#misc#msg#warn(msg, s:script, string(name), fnamemodify(path, ':~')) + let msg = "session.vim %s: Failed to delete %s session at %s!" + call xolox#misc#msg#warn(msg, g:session_version, string(name), fnamemodify(path, ':~')) else call s:unlock_session(path) - let msg = "%s: Deleted %s session at %s." - call xolox#misc#msg#info(msg, s:script, string(name), fnamemodify(path, ':~')) + let msg = "session.vim %s: Deleted %s session at %s." + call xolox#misc#msg#info(msg, g:session_version, string(name), fnamemodify(path, ':~')) endif endif endif @@ -404,13 +402,13 @@ function! xolox#session#close_cmd(bang, silent) abort " {{{2 unlet! s:session_is_dirty if v:this_session == '' if !a:silent - let msg = "%s: Closed session." - call xolox#misc#msg#info(msg, s:script) + let msg = "session.vim %s: Closed session." + call xolox#misc#msg#info(msg, g:session_version) endif else if !a:silent - let msg = "%s: Closed session %s." - call xolox#misc#msg#info(msg, s:script, fnamemodify(v:this_session, ':~')) + let msg = "session.vim %s: Closed session %s." + call xolox#misc#msg#info(msg, g:session_version, fnamemodify(v:this_session, ':~')) endif let v:this_session = '' endif @@ -419,8 +417,8 @@ endfunction function! xolox#session#restart_cmd(bang, args) abort " {{{2 if !has('gui_running') - let msg = "%s: The :RestartVim command only works in graphical Vim!" - call xolox#misc#msg#warn(msg, s:script) + let msg = "session.vim %s: The :RestartVim command only works in graphical Vim!" + call xolox#misc#msg#warn(msg, g:session_version) else let name = s:get_name('', 0) if name == '' | let name = 'restart' | endif @@ -513,7 +511,7 @@ endfunction function! s:last_session_persist(name) if g:session_default_to_last if writefile([a:name], s:last_session_file()) != 0 - call xolox#misc#msg#warn("Failed to persist name of last used session!") + call xolox#misc#msg#warn("session.vim %s: Failed to persist name of last used session!", g:session_version) endif endif endfunction @@ -561,9 +559,9 @@ function! s:session_is_locked(session_path, ...) let lines = readfile(lock_file) if lines[0] !=? v:servername if a:0 >= 1 - let msg = "%s: The %s session is locked by another Vim instance named %s! Use :%s! to override." + let msg = "session.vim %s: The %s session is locked by another Vim instance named %s! Use :%s! to override." let name = string(fnamemodify(a:session_path, ':t:r')) - call xolox#misc#msg#warn(msg, s:script, name, string(lines[0]), a:1) + call xolox#misc#msg#warn(msg, g:session_version, name, string(lines[0]), a:1) endif return 1 endif diff --git a/plugin/session.vim b/plugin/session.vim index f716bfc..f7af47c 100644 --- a/plugin/session.vim +++ b/plugin/session.vim @@ -1,8 +1,7 @@ " Vim script " Author: Peter Odding -" Last Change: June 13, 2011 +" Last Change: June 18, 2011 " URL: http://peterodding.com/code/vim/session/ -" Version: 1.4.8 " Support for automatic update using the GLVS plug-in. " GetLatestVimScripts: 3150 1 :AutoInstall: session.zip @@ -12,6 +11,8 @@ if &cp || exists('g:loaded_session') finish endif +let g:session_version = '1.4.9' + " When you start Vim without opening any files the plug-in will prompt you " whether you want to load the default session. Other supported values for " this option are 'yes' (to load the default session without prompting) and @@ -50,8 +51,8 @@ if !isdirectory(s:directory) call mkdir(s:directory, 'p') endif if filewritable(s:directory) != 2 - let s:msg = "session.vim: The sessions directory %s isn't writable!" - call xolox#misc#msg#warn(s:msg, string(s:directory)) + let s:msg = "session.vim %s: The sessions directory %s isn't writable!" + call xolox#misc#msg#warn(s:msg, g:session_version, string(s:directory)) unlet s:msg finish endif