From 28a1eafbbf20fb6aeaa94ffbc8b18a7f4947b294 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Thu, 2 Jun 2011 00:13:52 +0200 Subject: [PATCH] =?UTF-8?q?Make=20it=20possible=20to=20disable=20automatic?= =?UTF-8?q?=20loading/saving=20(suggested=20by=20Tommi=20Kivel=C3=A4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- autoload/xolox/session.vim | 12 ++++++++---- doc/session.txt | 22 ++++++++++++---------- plugin/session.vim | 18 ++++++++++++------ 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7a99cf2..a4f3cdd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/autoload/xolox/session.vim b/autoload/xolox/session.vim index b8df7c5..ec4054c 100644 --- a/autoload/xolox/session.vim +++ b/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(':p:~') @@ -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. @@ -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?" @@ -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 diff --git a/doc/session.txt b/doc/session.txt index b83b920..332b120 100644 --- a/doc/session.txt +++ b/doc/session.txt @@ -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 @@ -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 diff --git a/plugin/session.vim b/plugin/session.vim index 7faefe9..06f905b 100644 --- a/plugin/session.vim +++ b/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 @@ -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