Skip to content

Commit f56fe44

Browse files
committed
Make :RestartVim preserve $VIM and $VIMRUNTIME (issue #9)
1 parent 1ed64d2 commit f56fe44

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ By default this option is set to `'prompt'`. When you've opened a session and yo
9898

9999
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

101+
### The `g:session_restart_environment` option
102+
103+
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.
104+
101105
### The `g:loaded_session` option
102106

103107
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]:

autoload/xolox/session.vim

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

6-
let g:xolox#session#version = '1.4.19'
6+
let g:xolox#session#version = '1.4.20'
77

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

@@ -259,6 +259,7 @@ function! xolox#session#auto_unlock() " {{{2
259259
endfunction
260260

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

462463
function! xolox#session#restart_cmd(bang, args) abort " {{{2
463464
if !has('gui_running')
465+
" In console Vim we can't start a new Vim and kill the old one...
464466
let msg = "session.vim %s: The :RestartVim command only works in graphical Vim!"
465467
call xolox#misc#msg#warn(msg, g:xolox#session#version)
466468
else
@@ -473,12 +475,16 @@ function! xolox#session#restart_cmd(bang, args) abort " {{{2
473475
if !empty(args)
474476
let command .= ' -c ' . shellescape(args)
475477
endif
476-
if has('win32') || has('win64')
478+
if xolox#misc#os#is_win()
477479
execute '!start' command
478480
else
479-
let term = shellescape(fnameescape($TERM))
480-
let encoding = "--cmd ':set enc=" . escape(&enc, '\ ') . "'"
481-
silent execute '! TERM=' . term command encoding '&'
481+
let cmdline = []
482+
for variable in g:session_restart_environment
483+
call add(cmdline, variable . '=' . shellescape(fnameescape(eval('$' . variable))))
484+
endfor
485+
call add(cmdline, command)
486+
call add(cmdline, printf("--cmd ':set enc=%s'", escape(&enc, '\ ')))
487+
silent execute '!' join(cmdline, ' ') '&'
482488
endif
483489
execute 'CloseSession' . a:bang
484490
silent quitall

doc/session.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ instead of the default session. Note that the session plug-in will still show
188188
you the dialog asking whether you want to restore the last used session. To
189189
get rid of the dialog you have to set |g:session_autoload| to 'yes'.
190190

191+
-------------------------------------------------------------------------------
192+
The *g:session_restart_environment* option
193+
194+
This option is a list of environment variable names (without the dollar signs)
195+
that the |:RestartVim| command will pass on to the new instance of Vim. This
196+
option is only useful on UNIX. By default the three environment variables
197+
'$TERM', '$VIM' and '$VIMRUNTIME' are included in this list.
198+
191199
-------------------------------------------------------------------------------
192200
The *g:loaded_session* option
193201

plugin/session.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim script
22
" Author: Peter Odding
3-
" Last Change: September 28, 2011
3+
" Last Change: October 1, 2011
44
" URL: http://peterodding.com/code/vim/session/
55

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

37+
" On UNIX the :RestartVim command will pass the following environment
38+
" variables on to the new instance of Vim.
39+
if !exists('g:session_restart_environment')
40+
let g:session_restart_environment = ['TERM', 'VIM', 'VIMRUNTIME']
41+
endif
42+
3743
" The default directory where session scripts are stored.
3844
if !exists('g:session_directory')
3945
if xolox#misc#os#is_win()

0 commit comments

Comments
 (0)