Skip to content

Commit 7186722

Browse files
committed
Add session_default_overwrite option (see readme for details)
See also issue #62 on GitHub: #62
1 parent 70c89aa commit 7186722

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ This option controls the location of your session scripts. Its default value is
131131

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

134+
### The `g:session_default_overwrite` option
135+
136+
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).
137+
134138
### The `g:session_extension` option
135139

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

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

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

autoload/xolox/session.vim

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" Last Change: July 4, 2013
55
" URL: http://peterodding.com/code/vim/session/
66

7-
let g:xolox#session#version = '2.4.5'
7+
let g:xolox#session#version = '2.4.6'
88

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

@@ -430,18 +430,23 @@ function! xolox#session#auto_save() " {{{2
430430
let name = xolox#session#find_current_session()
431431
" If no session is active and the user doesn't have any sessions yet, help
432432
" them get started by suggesting to create the default session.
433-
if empty(name) && empty(xolox#session#get_names())
433+
if empty(name) && (empty(xolox#session#get_names()) || g:session_default_overwrite)
434434
let name = g:session_default_name
435435
endif
436-
" Prompt the user to save the active or first session?
436+
" Prompt the user to save the active/first/default session?
437437
if !empty(name)
438438
let is_tab_scoped = xolox#session#is_tab_scoped()
439439
let msg = "Do you want to save your %s before quitting Vim?"
440440
if s:prompt(printf(msg, xolox#session#get_label(name, is_tab_scoped)), ['&Yes', '&No'], 'g:session_autosave') == 1
441+
if g:session_default_overwrite && (name == g:session_default_overwrite)
442+
let bang = '!'
443+
else
444+
let bang = ''
445+
endif
441446
if is_tab_scoped
442-
call xolox#session#save_tab_cmd(name, '', 'SaveTabSession')
447+
call xolox#session#save_tab_cmd(name, bang, 'SaveTabSession')
443448
else
444-
call xolox#session#save_cmd(name, '', 'SaveSession')
449+
call xolox#session#save_cmd(name, bang, 'SaveSession')
445450
endif
446451
endif
447452
endif

doc/session.txt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ Contents ~
2121
1. The |sessionoptions| setting
2222
2. The |g:session_directory| option
2323
3. The |g:session_default_name| option
24-
4. The |g:session_extension| option
25-
5. The |g:session_autoload| option
26-
6. The |g:session_autosave| option
27-
7. The |g:session_autosave_periodic| option
28-
8. The |g:session_verbose_messages| option
29-
9. The |g:session_default_to_last| option
30-
10. The |g:session_persist_globals| option
31-
11. The |g:session_restart_environment| option
32-
12. The |g:session_command_aliases| option
33-
13. The |g:loaded_session| 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_globals| option
32+
12. The |g:session_restart_environment| option
33+
13. The |g:session_command_aliases| option
34+
14. The |g:loaded_session| option
3435
5. Compatibility with other plug-ins |session-compatibility-with-other-plug-ins|
3536
6. Known issues |session-known-issues|
3637
7. Function reference |session-function-reference|
@@ -304,6 +305,12 @@ The *g:session_default_name* option
304305
The name of the default session without directory or filename extension (you'll
305306
never guess what the default is).
306307

308+
-------------------------------------------------------------------------------
309+
The *g:session_default_overwrite* option
310+
311+
If you set this to true (1), every Vim instance without an explicit session
312+
loaded will overwrite the default session (the last Vim instance wins).
313+
307314
-------------------------------------------------------------------------------
308315
The *g:session_extension* option
309316

@@ -477,7 +484,7 @@ might take a while...)
477484
Function reference ~
478485

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

482489
-------------------------------------------------------------------------------
483490
*session-public-api-for-vim-notes-plug-in*

plugin/session.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ if !exists('g:session_default_name')
3232
let g:session_default_name = 'default'
3333
endif
3434

35+
" If you set this to 1 (true), every Vim instance without an explicit session
36+
" loaded will overwrite the default session (the last Vim instance wins).
37+
if !exists('g:session_default_overwrite')
38+
let g:session_default_overwrite = 0
39+
endif
40+
3541
" The file extension of session scripts.
3642
if !exists('g:session_extension')
3743
let g:session_extension = '.vim'

0 commit comments

Comments
 (0)