Skip to content

Commit

Permalink
Add session_default_overwrite option (see readme for details)
Browse files Browse the repository at this point in the history
See also issue #62 on GitHub:
  #62
  • Loading branch information
xolox committed Jul 3, 2013
1 parent 70c89aa commit 7186722
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -131,6 +131,10 @@ This option controls the location of your session scripts. Its default value is

The name of the default session without directory or filename extension (you'll never guess what the default is).

### The `g:session_default_overwrite` option

If you set this to true (1), every Vim instance without an explicit session loaded will overwrite the default session (the last Vim instance wins).

### The `g:session_extension` option

The filename extension of session scripts. This should include the dot that separates the basename from the extension. Defaults to '.vim'.
Expand Down Expand Up @@ -236,7 +240,7 @@ Recently this plug-in switched from reimplementing [:mksession][mksession] to ac
<!-- Start of generated documentation -->

The documentation of the 34 functions below was extracted from
1 Vim scripts on July 4, 2013 at 00:27.
1 Vim scripts on July 4, 2013 at 01:25.

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

Expand Down
15 changes: 10 additions & 5 deletions autoload/xolox/session.vim
Expand Up @@ -4,7 +4,7 @@
" Last Change: July 4, 2013
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '2.4.5'
let g:xolox#session#version = '2.4.6'

" Public API for session persistence. {{{1

Expand Down Expand Up @@ -430,18 +430,23 @@ function! xolox#session#auto_save() " {{{2
let name = xolox#session#find_current_session()
" If no session is active and the user doesn't have any sessions yet, help
" them get started by suggesting to create the default session.
if empty(name) && empty(xolox#session#get_names())
if empty(name) && (empty(xolox#session#get_names()) || g:session_default_overwrite)
let name = g:session_default_name
endif
" Prompt the user to save the active or first session?
" Prompt the user to save the active/first/default session?
if !empty(name)
let is_tab_scoped = xolox#session#is_tab_scoped()
let msg = "Do you want to save your %s before quitting Vim?"
if s:prompt(printf(msg, xolox#session#get_label(name, is_tab_scoped)), ['&Yes', '&No'], 'g:session_autosave') == 1
if g:session_default_overwrite && (name == g:session_default_overwrite)
let bang = '!'
else
let bang = ''
endif
if is_tab_scoped
call xolox#session#save_tab_cmd(name, '', 'SaveTabSession')
call xolox#session#save_tab_cmd(name, bang, 'SaveTabSession')
else
call xolox#session#save_cmd(name, '', 'SaveSession')
call xolox#session#save_cmd(name, bang, 'SaveSession')
endif
endif
endif
Expand Down
29 changes: 18 additions & 11 deletions doc/session.txt
Expand Up @@ -21,16 +21,17 @@ Contents ~
1. The |sessionoptions| setting
2. The |g:session_directory| option
3. The |g:session_default_name| option
4. The |g:session_extension| option
5. The |g:session_autoload| option
6. The |g:session_autosave| option
7. The |g:session_autosave_periodic| option
8. The |g:session_verbose_messages| option
9. The |g:session_default_to_last| option
10. The |g:session_persist_globals| option
11. The |g:session_restart_environment| option
12. The |g:session_command_aliases| option
13. The |g:loaded_session| 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_globals| option
12. The |g:session_restart_environment| option
13. The |g:session_command_aliases| option
14. 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 @@ -304,6 +305,12 @@ 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).

-------------------------------------------------------------------------------
The *g:session_default_overwrite* option

If you set this to true (1), every Vim instance without an explicit session
loaded will overwrite the default session (the last Vim instance wins).

-------------------------------------------------------------------------------
The *g:session_extension* option

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

The documentation of the 34 functions below was extracted from 1 Vim scripts on
July 4, 2013 at 00:27.
July 4, 2013 at 01:25.

-------------------------------------------------------------------------------
*session-public-api-for-vim-notes-plug-in*
Expand Down
6 changes: 6 additions & 0 deletions plugin/session.vim
Expand Up @@ -32,6 +32,12 @@ if !exists('g:session_default_name')
let g:session_default_name = 'default'
endif

" If you set this to 1 (true), every Vim instance without an explicit session
" loaded will overwrite the default session (the last Vim instance wins).
if !exists('g:session_default_overwrite')
let g:session_default_overwrite = 0
endif

" The file extension of session scripts.
if !exists('g:session_extension')
let g:session_extension = '.vim'
Expand Down

0 comments on commit 7186722

Please sign in to comment.