Skip to content

Commit d833471

Browse files
committed
Try to improve user feedback when sessions are locked
See also: #87
1 parent f13514a commit d833471

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
256256
<!-- Start of generated documentation -->
257257

258258
The documentation of the 37 functions below was extracted from
259-
2 Vim scripts on July 6, 2014 at 22:23.
259+
2 Vim scripts on July 7, 2014 at 01:17.
260260

261261
### Public API for the vim-session plug-in
262262

autoload/xolox/session.vim

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
" Public API for the vim-session plug-in.
22
"
33
" Author: Peter Odding
4-
" Last Change: July 6, 2014
4+
" Last Change: July 7, 2014
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.6'
7+
let g:xolox#session#version = '2.6.1'
88

99
" Public API for session persistence. {{{1
1010

@@ -413,7 +413,7 @@ function! xolox#session#auto_load() " {{{2
413413
" Default to the last used session or the default session?
414414
let [has_last_session, session] = s:get_last_or_default_session()
415415
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')
417417
" Compose the message for the prompt.
418418
let is_default_session = (session == g:session_default_name)
419419
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
554554
let msg = "session.vim %s: The %s session at %s doesn't exist!"
555555
call xolox#misc#msg#warn(msg, g:xolox#session#version, string(name), fnamemodify(path, ':~'))
556556
return 0
557-
elseif a:bang == '!' || !s:session_is_locked(path, a:command)
557+
elseif a:bang == '!' || !s:session_is_locked(name, a:command)
558558
let oldcwd = s:nerdtree_persist()
559559
call xolox#session#close_cmd(a:bang, 1, name != xolox#session#find_current_session(), a:command)
560560
call s:lock_session(path)
@@ -612,7 +612,7 @@ function! xolox#session#save_cmd(name, bang, command) abort " {{{2
612612
endif
613613
let path = xolox#session#name_to_path(name)
614614
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)
616616
let lines = []
617617
call xolox#session#save_session(lines, friendly_path)
618618
if xolox#misc#os#is_win() && !xolox#session#options_include('unix')
@@ -647,7 +647,7 @@ function! xolox#session#delete_cmd(name, bang) " {{{2
647647
if !filereadable(path)
648648
let msg = "session.vim %s: The %s session at %s doesn't exist!"
649649
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')
651651
if delete(path) != 0
652652
let msg = "session.vim %s: Failed to delete %s session at %s!"
653653
call xolox#misc#msg#warn(msg, g:xolox#session#version, string(name), fnamemodify(path, ':~'))
@@ -1030,7 +1030,7 @@ endfunction
10301030

10311031
function! s:lock_session(session_path)
10321032
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())
10341034
if index(s:lock_files, lock_file) == -1
10351035
call add(s:lock_files, lock_file)
10361036
endif
@@ -1049,13 +1049,13 @@ function! s:unlock_session(session_path)
10491049
endif
10501050
endfunction
10511051

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'
10541055
if filereadable(lock_file)
10551056
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)]
10591059
if this_instance == other_instance
10601060
" Session belongs to current Vim instance and tab page.
10611061
return 0
@@ -1073,11 +1073,10 @@ function! s:session_is_locked(session_path, ...)
10731073
else
10741074
call add(arguments, 'with PID ' . other_instance['pid'])
10751075
endif
1076+
let msg .= " If that doesn't seem right maybe you forcefully closed Vim or it crashed?"
10761077
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])
10811080
call call('xolox#misc#msg#warn', [msg] + arguments)
10821081
return 1
10831082
endif

doc/session.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ might take a while...)
513513
Function reference ~
514514

515515
The documentation of the 37 functions below was extracted from 2 Vim scripts on
516-
July 6, 2014 at 22:23.
516+
July 7, 2014 at 01:17.
517517

518518
-------------------------------------------------------------------------------
519519
*public-api-for-vim-session-plug-in*

0 commit comments

Comments
 (0)