1
1
" Public API for the vim-session plug-in.
2
2
"
3
3
" Author: Peter Odding
4
- " Last Change: July 6 , 2014
4
+ " Last Change: July 7 , 2014
5
5
" URL: http://peterodding.com/code/vim/session/
6
6
7
- let g: xolox #session#version = ' 2.6'
7
+ let g: xolox #session#version = ' 2.6.1 '
8
8
9
9
" Public API for session persistence. {{{1
10
10
@@ -413,7 +413,7 @@ function! xolox#session#auto_load() " {{{2
413
413
" Default to the last used session or the default session?
414
414
let [has_last_session, session] = s: get_last_or_default_session ()
415
415
let path = xolox#session#name_to_path (session)
416
- if (g: session_default_to_last == 0 || has_last_session) && filereadable (path ) && ! s: session_is_locked (path )
416
+ if (g: session_default_to_last == 0 || has_last_session) && filereadable (path ) && ! s: session_is_locked (session, ' OpenSession ' )
417
417
" Compose the message for the prompt.
418
418
let is_default_session = (session == g: session_default_name )
419
419
let msg = printf (" Do you want to restore your %s editing session%s?" ,
@@ -554,7 +554,7 @@ function! xolox#session#open_cmd(name, bang, command) abort " {{{2
554
554
let msg = " session.vim %s: The %s session at %s doesn't exist!"
555
555
call xolox#misc#msg#warn (msg, g: xolox #session#version , string (name), fnamemodify (path , ' :~' ))
556
556
return 0
557
- elseif a: bang == ' !' || ! s: session_is_locked (path , a: command )
557
+ elseif a: bang == ' !' || ! s: session_is_locked (name , a: command )
558
558
let oldcwd = s: nerdtree_persist ()
559
559
call xolox#session#close_cmd (a: bang , 1 , name != xolox#session#find_current_session (), a: command )
560
560
call s: lock_session (path )
@@ -612,7 +612,7 @@ function! xolox#session#save_cmd(name, bang, command) abort " {{{2
612
612
endif
613
613
let path = xolox#session#name_to_path (name)
614
614
let friendly_path = fnamemodify (path , ' :~' )
615
- if a: bang == ' !' || ! s: session_is_locked (path , a: command )
615
+ if a: bang == ' !' || ! s: session_is_locked (name , a: command )
616
616
let lines = []
617
617
call xolox#session#save_session (lines , friendly_path)
618
618
if xolox#misc#os#is_win () && ! xolox#session#options_include (' unix' )
@@ -647,7 +647,7 @@ function! xolox#session#delete_cmd(name, bang) " {{{2
647
647
if ! filereadable (path )
648
648
let msg = " session.vim %s: The %s session at %s doesn't exist!"
649
649
call xolox#misc#msg#warn (msg, g: xolox #session#version , string (name), fnamemodify (path , ' :~' ))
650
- elseif a: bang == ' !' || ! s: session_is_locked (path , ' DeleteSession' )
650
+ elseif a: bang == ' !' || ! s: session_is_locked (name , ' DeleteSession' )
651
651
if delete (path ) != 0
652
652
let msg = " session.vim %s: Failed to delete %s session at %s!"
653
653
call xolox#misc#msg#warn (msg, g: xolox #session#version , string (name), fnamemodify (path , ' :~' ))
@@ -1030,7 +1030,7 @@ endfunction
1030
1030
1031
1031
function ! s: lock_session (session_path)
1032
1032
let lock_file = a: session_path . ' .lock'
1033
- if writefile ([ string ( s: vim_instance_id ())], lock_file) == 0
1033
+ if xolox#misc#persist#save (lock_file, s: vim_instance_id ())
1034
1034
if index (s: lock_files , lock_file) == -1
1035
1035
call add (s: lock_files , lock_file)
1036
1036
endif
@@ -1049,13 +1049,13 @@ function! s:unlock_session(session_path)
1049
1049
endif
1050
1050
endfunction
1051
1051
1052
- function ! s: session_is_locked (session_path, ... )
1053
- let lock_file = a: session_path . ' .lock'
1052
+ function ! s: session_is_locked (session_name, command )
1053
+ let session_path = xolox#session#name_to_path (a: session_name )
1054
+ let lock_file = session_path . ' .lock'
1054
1055
if filereadable (lock_file)
1055
1056
let this_instance = s: vim_instance_id ()
1056
- let other_instance = eval (get (readfile (lock_file), 0 , ' {}' ))
1057
- let name = string (fnamemodify (a: session_path , ' :t:r' ))
1058
- let arguments = [g: xolox #session#version , name]
1057
+ let other_instance = xolox#misc#persist#load (lock_file)
1058
+ let arguments = [g: xolox #session#version , string (a: session_name )]
1059
1059
if this_instance == other_instance
1060
1060
" Session belongs to current Vim instance and tab page.
1061
1061
return 0
@@ -1073,11 +1073,10 @@ function! s:session_is_locked(session_path, ...)
1073
1073
else
1074
1074
call add (arguments, ' with PID ' . other_instance[' pid' ])
1075
1075
endif
1076
+ let msg .= " If that doesn't seem right maybe you forcefully closed Vim or it crashed?"
1076
1077
endif
1077
- if exists (' a:1' )
1078
- let msg .= " Use :%s! to override."
1079
- call add (arguments, a: 1 )
1080
- endif
1078
+ let msg .= " Use the command ':%s! %s' to override."
1079
+ call extend (arguments, [a: command , a: session_name ])
1081
1080
call call (' xolox#misc#msg#warn' , [msg] + arguments)
1082
1081
return 1
1083
1082
endif
0 commit comments