Skip to content

Commit

Permalink
Make :RestartVim preserve $VIM and $VIMRUNTIME (issue #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Oct 1, 2011
1 parent 1ed64d2 commit f56fe44
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -98,6 +98,10 @@ By default this option is set to `'prompt'`. When you've opened a session and yo

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:session_restart_environment` option

This option is a list of environment variable names (without the dollar signs) that the `:RestartVim` command will pass on to the new instance of Vim. This option is only useful on UNIX. By default the three environment variables `$TERM`, `$VIM` and `$VIMRUNTIME` are included in this list.

### The `g:loaded_session` option

This variable isn't really an option but if you want to avoid loading the `session.vim` plug-in you can set this variable to any value in your [vimrc script] [vimrc]:
Expand Down
18 changes: 12 additions & 6 deletions autoload/xolox/session.vim
@@ -1,9 +1,9 @@
" Vim script
" Author: Peter Odding
" Last Change: September 28, 2011
" Last Change: October 1, 2011
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '1.4.19'
let g:xolox#session#version = '1.4.20'

" Public API for session persistence. {{{1

Expand Down Expand Up @@ -259,6 +259,7 @@ function! xolox#session#auto_unlock() " {{{2
endfunction

function! xolox#session#auto_dirty_check() " {{{2
" TODO Why execute this on every buffer change?! Instead execute it only when we want to know whether the session is dirty!
" This function is called each time a BufEnter event fires to detect when
" the current tab page (or the buffer list) is changed in some way. This
" enables the plug-in to not bother with the auto-save dialog when the
Expand Down Expand Up @@ -461,6 +462,7 @@ endfunction

function! xolox#session#restart_cmd(bang, args) abort " {{{2
if !has('gui_running')
" In console Vim we can't start a new Vim and kill the old one...
let msg = "session.vim %s: The :RestartVim command only works in graphical Vim!"
call xolox#misc#msg#warn(msg, g:xolox#session#version)
else
Expand All @@ -473,12 +475,16 @@ function! xolox#session#restart_cmd(bang, args) abort " {{{2
if !empty(args)
let command .= ' -c ' . shellescape(args)
endif
if has('win32') || has('win64')
if xolox#misc#os#is_win()
execute '!start' command
else
let term = shellescape(fnameescape($TERM))
let encoding = "--cmd ':set enc=" . escape(&enc, '\ ') . "'"
silent execute '! TERM=' . term command encoding '&'
let cmdline = []
for variable in g:session_restart_environment
call add(cmdline, variable . '=' . shellescape(fnameescape(eval('$' . variable))))
endfor
call add(cmdline, command)
call add(cmdline, printf("--cmd ':set enc=%s'", escape(&enc, '\ ')))
silent execute '!' join(cmdline, ' ') '&'
endif
execute 'CloseSession' . a:bang
silent quitall
Expand Down
8 changes: 8 additions & 0 deletions doc/session.txt
Expand Up @@ -188,6 +188,14 @@ 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:session_restart_environment* option

This option is a list of environment variable names (without the dollar signs)
that the |:RestartVim| command will pass on to the new instance of Vim. This
option is only useful on UNIX. By default the three environment variables
'$TERM', '$VIM' and '$VIMRUNTIME' are included in this list.

-------------------------------------------------------------------------------
The *g:loaded_session* option

Expand Down
8 changes: 7 additions & 1 deletion plugin/session.vim
@@ -1,6 +1,6 @@
" Vim script
" Author: Peter Odding
" Last Change: September 28, 2011
" Last Change: October 1, 2011
" URL: http://peterodding.com/code/vim/session/

" Support for automatic update using the GLVS plug-in.
Expand Down Expand Up @@ -34,6 +34,12 @@ if !exists('g:session_default_to_last')
let g:session_default_to_last = 0
endif

" On UNIX the :RestartVim command will pass the following environment
" variables on to the new instance of Vim.
if !exists('g:session_restart_environment')
let g:session_restart_environment = ['TERM', 'VIM', 'VIMRUNTIME']
endif

" The default directory where session scripts are stored.
if !exists('g:session_directory')
if xolox#misc#os#is_win()
Expand Down

0 comments on commit f56fe44

Please sign in to comment.