Skip to content

Commit 28a1eaf

Browse files
committed
Make it possible to disable automatic loading/saving (suggested by Tommi Kivelä)
1 parent e6a4ff2 commit 28a1eaf

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ This option controls the location of your session scripts. Its default value is
8888

8989
### The `g:session_autoload` option
9090

91-
By default this option is set to false (0). This means that when you start Vim without opening any files and the `default` session script exists, the `session.vim` plug-in will ask whether you want to restore your default session. When you set this option to true (1) and you start Vim without opening any files the default session will be restored without a prompt.
91+
By default this option is set to `'prompt'`. This means that when you start Vim without opening any files and the `default` session script exists, the session plug-in will ask whether you want to restore your default session. When you set this option to `'yes'` and you start Vim without opening any files the default session will be restored without a prompt. To completely disable automatic loading you can set this option to `'no'`.
9292

9393
### The `g:session_autosave` option
9494

95-
By default this option is set to false (0). When you've opened a session and you quit Vim, the `session.vim` plug-in will ask whether you want to save the changes to your session. Set this option to true (1) to always automatically save open sessions when you quit Vim.
95+
By default this option is set to `'prompt'`. When you've opened a session and you quit Vim, the session plug-in will ask whether you want to save the changes to your session. Set this option to `'yes'` to always automatically save open sessions when you quit Vim. To completely disable automatic saving you can set this option to `'no'`.
9696

9797
### The `g:session_default_to_last` option
9898

99-
By default this option is set to false (0). When you set this option to true (1) and you start Vim, the session plug-in will open your last used session instead of the default session. Note that the session plug-in will still show you the dialog asking whether you want to restore the last used session. To get rid of the dialog you have to set `g:session_autoload` to true (1).
99+
By default this option is set to false (0). When you set this option to true (1) and you start Vim, the session plug-in will open your last used session instead of the default session. Note that the session plug-in will still show you the dialog asking whether you want to restore the last used session. To get rid of the dialog you have to set `g:session_autoload` to `'yes'`.
100100

101101
### The `g:loaded_session` option
102102

autoload/xolox/session.vim

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim script
22
" Author: Peter Odding
3-
" Last Change: May 26, 2011
3+
" Last Change: June 1, 2011
44
" URL: http://peterodding.com/code/vim/session/
55

66
let s:script = expand('<sfile>:p:~')
@@ -185,6 +185,9 @@ endfunction
185185
" Automatic commands to manage the default session. {{{1
186186

187187
function! xolox#session#auto_load() " {{{2
188+
if g:session_autoload == 'no'
189+
return
190+
endif
188191
" Check that the user has started Vim without editing any files.
189192
if bufnr('$') == 1 && bufname('%') == '' && !&mod && getline(1, '$') == ['']
190193
" Check whether a session matching the user-specified server name exists.
@@ -210,7 +213,7 @@ function! xolox#session#auto_load() " {{{2
210213
endfunction
211214

212215
function! xolox#session#auto_save() " {{{2
213-
if !v:dying
216+
if !v:dying && g:session_autosave != 'no'
214217
let name = s:get_name('', 0)
215218
if name != '' && exists('s:session_is_dirty')
216219
let msg = "Do you want to save your editing session before quitting Vim?"
@@ -264,10 +267,11 @@ function! xolox#session#auto_dirty_check() " {{{2
264267
endfunction
265268

266269
function! s:prompt(msg, var) " {{{2
267-
if eval(a:var)
270+
let value = eval(a:var)
271+
if value == 'yes' || (type(value) != type('') && value)
268272
return 1
269273
else
270-
let format = "%s Note that you can permanently disable this dialog by adding the following line to your %s script:\n\n\t:let %s = 1"
274+
let format = "%s Note that you can permanently disable this dialog by adding the following line to your %s script:\n\n\t:let %s = 'no'"
271275
let vimrc = xolox#misc#os#is_win() ? '~\_vimrc' : '~/.vimrc'
272276
let prompt = printf(format, a:msg, vimrc, a:var)
273277
return confirm(prompt, "&Yes\n&No", 1, 'Question') == 1

doc/session.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,21 @@ directory ('$HOME' on UNIX, '%USERPROFILE%' on Windows).
163163
-------------------------------------------------------------------------------
164164
The *g:session_autoload* option
165165

166-
By default this option is set to false (0). This means that when you start Vim
167-
without opening any files and the 'default' session script exists, the
168-
'session.vim' plug-in will ask whether you want to restore your default
169-
session. When you set this option to true (1) and you start Vim without
170-
opening any files the default session will be restored without a prompt.
166+
By default this option is set to 'prompt'. This means that when you start Vim
167+
without opening any files and the 'default' session script exists, the session
168+
plug-in will ask whether you want to restore your default session. When you
169+
set this option to 'yes' and you start Vim without opening any files the
170+
default session will be restored without a prompt. To completely disable
171+
automatic loading you can set this option to 'no'.
171172

172173
-------------------------------------------------------------------------------
173174
The *g:session_autosave* option
174175

175-
By default this option is set to false (0). When you've opened a session and
176-
you quit Vim, the 'session.vim' plug-in will ask whether you want to save the
177-
changes to your session. Set this option to true (1) to always automatically
178-
save open sessions when you quit Vim.
176+
By default this option is set to 'prompt'. When you've opened a session and
177+
you quit Vim, the session plug-in will ask whether you want to save the
178+
changes to your session. Set this option to 'yes' to always automatically save
179+
open sessions when you quit Vim. To completely disable automatic saving you
180+
can set this option to 'no'.
179181

180182
-------------------------------------------------------------------------------
181183
The *g:session_default_to_last* option
@@ -184,7 +186,7 @@ By default this option is set to false (0). When you set this option to true
184186
(1) and you start Vim, the session plug-in will open your last used session
185187
instead of the default session. Note that the session plug-in will still show
186188
you the dialog asking whether you want to restore the last used session. To
187-
get rid of the dialog you have to set |g:session_autoload| to true (1).
189+
get rid of the dialog you have to set |g:session_autoload| to 'yes'.
188190

189191
-------------------------------------------------------------------------------
190192
The *g:loaded_session* option

plugin/session.vim

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
" Vim script
22
" Author: Peter Odding
3-
" Last Change: May 26, 2011
3+
" Last Change: June 1, 2011
44
" URL: http://peterodding.com/code/vim/session/
5-
" Version: 1.4.4
5+
" Version: 1.4.5
66

77
" Support for automatic update using the GLVS plug-in.
88
" GetLatestVimScripts: 3150 1 :AutoInstall: session.zip
@@ -12,14 +12,20 @@ if &cp || exists('g:loaded_session')
1212
finish
1313
endif
1414

15-
" Automatic loading of the default session is disabled by default.
15+
" When you start Vim without opening any files the plug-in will prompt you
16+
" whether you want to load the default session. Other supported values for
17+
" this option are 'yes' (to load the default session without prompting) and
18+
" 'no' (don't prompt and don't load the default session).
1619
if !exists('g:session_autoload')
17-
let g:session_autoload = 0
20+
let g:session_autoload = 'prompt'
1821
endif
1922

20-
" Automatic saving of the default session is disabled by default.
23+
" When you quit Vim the plug-in will prompt you whether you want to save your
24+
" current session. Other supported values for this option are 'yes' (to save
25+
" the session without prompting) and 'no' (don't prompt and don't save the
26+
" session).
2127
if !exists('g:session_autosave')
22-
let g:session_autosave = 0
28+
let g:session_autosave = 'prompt'
2329
endif
2430

2531
" The session plug-in can automatically open sessions in three ways: based on

0 commit comments

Comments
 (0)