Skip to content

Commit 4fb9cdd

Browse files
committed
Resolve issue #101: Add support for lock directory configuration
See issue #101 on GitHub: #101
1 parent 6773a22 commit 4fb9cdd

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ Note that the vim-session plug-in automatically and unconditionally executes the
127127

128128
This option controls the location of your session scripts. Its default value is `~/.vim/sessions` (on UNIX) or `~\vimfiles\sessions` (on Windows). If you don't mind the default you don't have to do anything; the directory will be created for you. Note that a leading `~` is expanded to your current home directory (`$HOME` on UNIX, `%USERPROFILE%` on Windows).
129129

130+
### The `g:session_lock_directory` option
131+
132+
The vim-session plug-in uses lock files to prevent double loading of sessions. By default the lock files are stored in the same directory as the sessions. If you'd rather store lock files in a dedicated lock file directory you can use this option:
133+
134+
" Store lock files in a tmpfs that doesn't persist between reboots.
135+
let g:session_lock_directory = '/var/lock'
136+
130137
### The `g:session_default_name` option
131138

132139
The name of the default session without directory or filename extension (you'll never guess what the default is).
@@ -256,7 +263,7 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
256263
<!-- Start of generated documentation -->
257264

258265
The documentation of the 37 functions below was extracted from
259-
2 Vim scripts on July 30, 2014 at 22:23.
266+
2 Vim scripts on September 14, 2014 at 13:07.
260267

261268
### Public API for the vim-session plug-in
262269

autoload/xolox/session.vim

Lines changed: 15 additions & 5 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 30, 2014
4+
" Last Change: September 14, 2014
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.6.4'
7+
let g:xolox#session#version = '2.7'
88

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

@@ -1018,8 +1018,18 @@ function! s:vim_instance_id()
10181018
return id
10191019
endfunction
10201020

1021+
function! s:lock_file_path(session_path)
1022+
let directory = xolox#misc#option#get('session_lock_directory', '')
1023+
if !empty(directory)
1024+
let pathname = xolox#misc#path#merge(directory, xolox#misc#path#encode(a:session_path))
1025+
else
1026+
let pathname = a:session_path
1027+
endif
1028+
return pathname . '.lock'
1029+
endfunction
1030+
10211031
function! s:lock_session(session_path)
1022-
let lock_file = a:session_path . '.lock'
1032+
let lock_file = s:lock_file_path(a:session_path)
10231033
if xolox#misc#persist#save(lock_file, s:vim_instance_id())
10241034
if index(s:lock_files, lock_file) == -1
10251035
call add(s:lock_files, lock_file)
@@ -1029,7 +1039,7 @@ function! s:lock_session(session_path)
10291039
endfunction
10301040

10311041
function! s:unlock_session(session_path)
1032-
let lock_file = a:session_path . '.lock'
1042+
let lock_file = s:lock_file_path(a:session_path)
10331043
if delete(lock_file) == 0
10341044
let idx = index(s:lock_files, lock_file)
10351045
if idx >= 0
@@ -1041,7 +1051,7 @@ endfunction
10411051

10421052
function! s:session_is_locked(session_name, command)
10431053
let session_path = xolox#session#name_to_path(a:session_name)
1044-
let lock_file = session_path . '.lock'
1054+
let lock_file = s:lock_file_path(session_path)
10451055
if filereadable(lock_file)
10461056
let this_instance = s:vim_instance_id()
10471057
let other_instance = xolox#misc#persist#load(lock_file)

doc/session.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@ Contents ~
2020
4. Options |session-options|
2121
1. The |sessionoptions| setting
2222
2. The |g:session_directory| option
23-
3. The |g:session_default_name| option
24-
4. The |g:session_default_overwrite| option
25-
5. The |g:session_extension| option
26-
6. The |g:session_autoload| option
27-
7. The |g:session_autosave| option
28-
8. The |g:session_autosave_periodic| option
29-
9. The |g:session_verbose_messages| option
30-
10. The |g:session_default_to_last| option
31-
11. The |g:session_persist_colors| option
32-
12. The |g:session_persist_globals| option
33-
13. The |g:session_restart_environment| option
34-
14. The |g:session_command_aliases| option
35-
15. The |g:session_menu| option
36-
16. The |g:session_name_suggestion_function| option
37-
17. The |g:loaded_session| option
23+
3. The |g:session_lock_directory| option
24+
4. The |g:session_default_name| option
25+
5. The |g:session_default_overwrite| option
26+
6. The |g:session_extension| option
27+
7. The |g:session_autoload| option
28+
8. The |g:session_autosave| option
29+
9. The |g:session_autosave_periodic| option
30+
10. The |g:session_verbose_messages| option
31+
11. The |g:session_default_to_last| option
32+
12. The |g:session_persist_colors| option
33+
13. The |g:session_persist_globals| option
34+
14. The |g:session_restart_environment| option
35+
15. The |g:session_command_aliases| option
36+
16. The |g:session_menu| option
37+
17. The |g:session_name_suggestion_function| option
38+
18. The |g:loaded_session| option
3839
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
3940
6. Known issues |session-known-issues|
4041
7. Function reference |session-function-reference|
@@ -305,6 +306,17 @@ mind the default you don't have to do anything; the directory will be created
305306
for you. Note that a leading '~' is expanded to your current home directory
306307
('$HOME' on UNIX, '%USERPROFILE%' on Windows).
307308

309+
-------------------------------------------------------------------------------
310+
The *g:session_lock_directory* option
311+
312+
The vim-session plug-in uses lock files to prevent double loading of sessions.
313+
By default the lock files are stored in the same directory as the sessions. If
314+
you'd rather store lock files in a dedicated lock file directory you can use
315+
this option:
316+
>
317+
" Store lock files in a tmpfs that doesn't persist between reboots.
318+
let g:session_lock_directory = '/var/lock'
319+
<
308320
-------------------------------------------------------------------------------
309321
The *g:session_default_name* option
310322

@@ -513,7 +525,7 @@ might take a while...)
513525
Function reference ~
514526

515527
The documentation of the 37 functions below was extracted from 2 Vim scripts on
516-
July 30, 2014 at 22:23.
528+
September 14, 2014 at 13:07.
517529

518530
-------------------------------------------------------------------------------
519531
*public-api-for-vim-session-plug-in*

0 commit comments

Comments
 (0)