diff --git a/README.md b/README.md index 43209e2..a3889ef 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,13 @@ The vim-session plug-in uses lock files to prevent double loading of sessions. T 2. If the directory `/var/lock` exists and is writable that is used as a sane default. 3. As a sane fall back for platforms where `/var/lock` is not available the directory that stores the session scripts themselves is used. +### The `g:session_lock_enabled` option + +Depending on your workflow locking of editing sessions can get annoying at times, so if you don't care about opening a session more than once and potentially "losing a version of your session" then you can use this option to completely disable session locking as follows: + + " Disable all session locking - I know what I'm doing :-). + let g:session_lock_enabled = 0 + ### 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). @@ -263,8 +270,8 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac -The documentation of the 37 functions below was extracted from -2 Vim scripts on February 13, 2015 at 13:25. +The documentation of the 38 functions below was extracted from +2 Vim scripts on February 18, 2015 at 22:56. ### Public API for the vim-session plug-in @@ -471,6 +478,14 @@ scoped session. Saves a copy of the original value to be restored later. Restore the original value of Vim's [sessionoptions] [] option. +#### The `xolox#session#locking_enabled()` function + +Check whether session locking is enabled. Returns true (1) when locking is +enabled, false (0) otherwise. + +By default session locking is enabled but users can opt-out by setting +`g:session_lock_enabled` to false (0). + ### Example function for session name suggestions #### The `xolox#session#suggestions#vcs_feature_branch()` function diff --git a/autoload/xolox/session.vim b/autoload/xolox/session.vim index 1abf96c..6071c48 100644 --- a/autoload/xolox/session.vim +++ b/autoload/xolox/session.vim @@ -1,10 +1,10 @@ " Public API for the vim-session plug-in. " " Author: Peter Odding -" Last Change: February 13, 2015 +" Last Change: February 18, 2015 " URL: http://peterodding.com/code/vim/session/ -let g:xolox#session#version = '2.8' +let g:xolox#session#version = '2.9' " Public API for session persistence. {{{1 @@ -499,15 +499,17 @@ function! xolox#session#auto_unlock() " {{{2 " [VimLeavePre] [] automatic command event. " " [VimLeavePre]: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#VimLeavePre - let i = 0 - while i < len(s:lock_files) - let lock_file = s:lock_files[i] - if delete(lock_file) == 0 - call remove(s:lock_files, i) - else - let i += 1 - endif - endwhile + if xolox#session#locking_enabled() + let i = 0 + while i < len(s:lock_files) + let lock_file = s:lock_files[i] + if delete(lock_file) == 0 + call remove(s:lock_files, i) + else + let i += 1 + endif + endwhile + endif endfunction " Commands that enable users to manage multiple sessions. {{{1 @@ -1007,6 +1009,15 @@ if !exists('s:lock_files') let s:lock_files = [] endif +function! xolox#session#locking_enabled() + " Check whether session locking is enabled. Returns true (1) when locking is + " enabled, false (0) otherwise. + " + " By default session locking is enabled but users can opt-out by setting + " `g:session_lock_enabled` to false (0). + return xolox#misc#option#get('session_lock_enabled', 1) +endfunction + function! s:vim_instance_id() let id = {'pid': getpid()} if !empty(v:servername) @@ -1045,6 +1056,9 @@ function! s:lock_file_path(session_path) endfunction function! s:lock_session(session_path) + if !xolox#session#locking_enabled() + return 1 + endif 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 @@ -1055,6 +1069,9 @@ function! s:lock_session(session_path) endfunction function! s:unlock_session(session_path) + if !xolox#session#locking_enabled() + return 1 + endif let lock_file = s:lock_file_path(a:session_path) if delete(lock_file) == 0 let idx = index(s:lock_files, lock_file) @@ -1066,6 +1083,9 @@ function! s:unlock_session(session_path) endfunction function! s:session_is_locked(session_name, command) + if !xolox#session#locking_enabled() + return 0 + endif let session_path = xolox#session#name_to_path(a:session_name) let lock_file = s:lock_file_path(session_path) if filereadable(lock_file) diff --git a/doc/session.txt b/doc/session.txt index b2de080..64327f4 100644 --- a/doc/session.txt +++ b/doc/session.txt @@ -21,21 +21,22 @@ Contents ~ 1. The |sessionoptions| setting 2. The |g:session_directory| 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 + 4. The |g:session_lock_enabled| option + 5. The |g:session_default_name| option + 6. The |g:session_default_overwrite| option + 7. The |g:session_extension| option + 8. The |g:session_autoload| option + 9. The |g:session_autosave| option + 10. The |g:session_autosave_periodic| option + 11. The |g:session_verbose_messages| option + 12. The |g:session_default_to_last| option + 13. The |g:session_persist_colors| option + 14. The |g:session_persist_globals| option + 15. The |g:session_restart_environment| option + 16. The |g:session_command_aliases| option + 17. The |g:session_menu| option + 18. The |g:session_name_suggestion_function| option + 19. 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| @@ -65,6 +66,7 @@ Contents ~ 23. The |xolox#session#include_tabs()| function 24. The |xolox#session#change_tab_options()| function 25. The |xolox#session#restore_tab_options()| function + 26. The |xolox#session#locking_enabled()| function 2. Example function for session name suggestions |example-function-for-session-name-suggestions| 1. The |xolox#session#suggestions#vcs_feature_branch()| function 8. Contact |session-contact| @@ -322,6 +324,17 @@ factors: 3. As a sane fall back for platforms where '/var/lock' is not available the directory that stores the session scripts themselves is used. +------------------------------------------------------------------------------- +The *g:session_lock_enabled* option + +Depending on your workflow locking of editing sessions can get annoying at +times, so if you don't care about opening a session more than once and +potentially "losing a version of your session" then you can use this option to +completely disable session locking as follows: +> + " Disable all session locking - I know what I'm doing :-). + let g:session_lock_enabled = 0 +< ------------------------------------------------------------------------------- The *g:session_default_name* option @@ -529,8 +542,8 @@ might take a while...) *session-function-reference* Function reference ~ -The documentation of the 37 functions below was extracted from 2 Vim scripts on -February 13, 2015 at 13:25. +The documentation of the 38 functions below was extracted from 2 Vim scripts on +February 18, 2015 at 22:56. ------------------------------------------------------------------------------- *public-api-for-vim-session-plug-in* @@ -743,6 +756,15 @@ The *xolox#session#restore_tab_options()* function Restore the original value of Vim's sessionoptions (see |'sessionoptions'|) option. +------------------------------------------------------------------------------- +The *xolox#session#locking_enabled()* function + +Check whether session locking is enabled. Returns true (1) when locking is +enabled, false (0) otherwise. + +By default session locking is enabled but users can opt-out by setting +|g:session_lock_enabled| to false (0). + ------------------------------------------------------------------------------- *example-function-for-session-name-suggestions* Example function for session name suggestions ~