Skip to content

Commit

Permalink
Resolve issue #101: Add support for lock directory configuration
Browse files Browse the repository at this point in the history
See issue #101 on GitHub:
  #101
  • Loading branch information
xolox committed Sep 14, 2014
1 parent 6773a22 commit 4fb9cdd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ Note that the vim-session plug-in automatically and unconditionally executes the

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).

### The `g:session_lock_directory` option

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:

" Store lock files in a tmpfs that doesn't persist between reboots.
let g:session_lock_directory = '/var/lock'

### The `g:session_default_name` option

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

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

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

Expand Down
20 changes: 15 additions & 5 deletions autoload/xolox/session.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
" Public API for the vim-session plug-in.
"
" Author: Peter Odding
" Last Change: July 30, 2014
" Last Change: September 14, 2014
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '2.6.4'
let g:xolox#session#version = '2.7'

" Public API for session persistence. {{{1

Expand Down Expand Up @@ -1018,8 +1018,18 @@ function! s:vim_instance_id()
return id
endfunction

function! s:lock_file_path(session_path)
let directory = xolox#misc#option#get('session_lock_directory', '')
if !empty(directory)
let pathname = xolox#misc#path#merge(directory, xolox#misc#path#encode(a:session_path))
else
let pathname = a:session_path
endif
return pathname . '.lock'
endfunction

function! s:lock_session(session_path)
let lock_file = a:session_path . '.lock'
let lock_file = s:lock_file_path(a:session_path)
if xolox#misc#persist#save(lock_file, s:vim_instance_id())
if index(s:lock_files, lock_file) == -1
call add(s:lock_files, lock_file)
Expand All @@ -1029,7 +1039,7 @@ function! s:lock_session(session_path)
endfunction

function! s:unlock_session(session_path)
let lock_file = a:session_path . '.lock'
let lock_file = s:lock_file_path(a:session_path)
if delete(lock_file) == 0
let idx = index(s:lock_files, lock_file)
if idx >= 0
Expand All @@ -1041,7 +1051,7 @@ endfunction

function! s:session_is_locked(session_name, command)
let session_path = xolox#session#name_to_path(a:session_name)
let lock_file = session_path . '.lock'
let lock_file = s:lock_file_path(session_path)
if filereadable(lock_file)
let this_instance = s:vim_instance_id()
let other_instance = xolox#misc#persist#load(lock_file)
Expand Down
44 changes: 28 additions & 16 deletions doc/session.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ Contents ~
4. Options |session-options|
1. The |sessionoptions| setting
2. The |g:session_directory| option
3. The |g:session_default_name| option
4. The |g:session_default_overwrite| option
5. The |g:session_extension| option
6. The |g:session_autoload| option
7. The |g:session_autosave| option
8. The |g:session_autosave_periodic| option
9. The |g:session_verbose_messages| option
10. The |g:session_default_to_last| option
11. The |g:session_persist_colors| option
12. The |g:session_persist_globals| option
13. The |g:session_restart_environment| option
14. The |g:session_command_aliases| option
15. The |g:session_menu| option
16. The |g:session_name_suggestion_function| option
17. The |g:loaded_session| option
3. The |g:session_lock_directory| option
4. The |g:session_default_name| option
5. The |g:session_default_overwrite| option
6. The |g:session_extension| option
7. The |g:session_autoload| option
8. The |g:session_autosave| option
9. The |g:session_autosave_periodic| option
10. The |g:session_verbose_messages| option
11. The |g:session_default_to_last| option
12. The |g:session_persist_colors| option
13. The |g:session_persist_globals| option
14. The |g:session_restart_environment| option
15. The |g:session_command_aliases| option
16. The |g:session_menu| option
17. The |g:session_name_suggestion_function| option
18. The |g:loaded_session| option
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
6. Known issues |session-known-issues|
7. Function reference |session-function-reference|
Expand Down Expand Up @@ -305,6 +306,17 @@ 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).

-------------------------------------------------------------------------------
The *g:session_lock_directory* option

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:
>
" Store lock files in a tmpfs that doesn't persist between reboots.
let g:session_lock_directory = '/var/lock'
<
-------------------------------------------------------------------------------
The *g:session_default_name* option

Expand Down Expand Up @@ -513,7 +525,7 @@ might take a while...)
Function reference ~

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

-------------------------------------------------------------------------------
*public-api-for-vim-session-plug-in*
Expand Down

0 comments on commit 4fb9cdd

Please sign in to comment.