Skip to content

Commit

Permalink
Make it possible to disable automatic loading/saving (suggested by To…
Browse files Browse the repository at this point in the history
…mmi Kivelä)
  • Loading branch information
xolox committed Jun 1, 2011
1 parent e6a4ff2 commit 28a1eaf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -88,15 +88,15 @@ This option controls the location of your session scripts. Its default value is

### The `g:session_autoload` option

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.
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'`.

### The `g:session_autosave` option

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.
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'`.

### The `g:session_default_to_last` option

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

### The `g:loaded_session` option

Expand Down
12 changes: 8 additions & 4 deletions autoload/xolox/session.vim
@@ -1,6 +1,6 @@
" Vim script
" Author: Peter Odding
" Last Change: May 26, 2011
" Last Change: June 1, 2011
" URL: http://peterodding.com/code/vim/session/

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

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

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

function! s:prompt(msg, var) " {{{2
if eval(a:var)
let value = eval(a:var)
if value == 'yes' || (type(value) != type('') && value)
return 1
else
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"
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'"
let vimrc = xolox#misc#os#is_win() ? '~\_vimrc' : '~/.vimrc'
let prompt = printf(format, a:msg, vimrc, a:var)
return confirm(prompt, "&Yes\n&No", 1, 'Question') == 1
Expand Down
22 changes: 12 additions & 10 deletions doc/session.txt
Expand Up @@ -163,19 +163,21 @@ directory ('$HOME' on UNIX, '%USERPROFILE%' on Windows).
-------------------------------------------------------------------------------
The *g:session_autoload* option

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

-------------------------------------------------------------------------------
The *g:session_autosave* option

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

-------------------------------------------------------------------------------
The *g:session_default_to_last* option
Expand All @@ -184,7 +186,7 @@ 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).
get rid of the dialog you have to set |g:session_autoload| to 'yes'.

-------------------------------------------------------------------------------
The *g:loaded_session* option
Expand Down
18 changes: 12 additions & 6 deletions plugin/session.vim
@@ -1,8 +1,8 @@
" Vim script
" Author: Peter Odding
" Last Change: May 26, 2011
" Last Change: June 1, 2011
" URL: http://peterodding.com/code/vim/session/
" Version: 1.4.4
" Version: 1.4.5

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

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

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

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

0 comments on commit 28a1eaf

Please sign in to comment.