Skip to content

Commit e6a4ff2

Browse files
committed
Restore NERDTree buffer after :CloseSession
Thanks to Brandon Martin for the bug report / feature request :-)
1 parent 3635adb commit e6a4ff2

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

autoload/xolox/session.vim

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ function! xolox#session#save_state(commands) " {{{2
109109
endtry
110110
endfunction
111111

112-
" Integration between :mksession, :NERDTree and :Project. {{{3
113-
114-
function! xolox#session#save_special_windows(session)
112+
function! xolox#session#save_special_windows(session) " {{{2
113+
" Integration between :mksession, :NERDTree and :Project.
115114
let tabpage = tabpagenr()
116115
let window = winnr()
117116
try
@@ -174,6 +173,15 @@ function! s:jump_to_window(session, tabpage, window)
174173
call add(a:session, a:window . 'wincmd w')
175174
endfunction
176175

176+
function! s:nerdtree_persist()
177+
" Remember current working directory and whether NERDTree is loaded.
178+
if exists('b:NERDTreeRoot')
179+
return 'NERDTree ' . fnameescape(b:NERDTreeRoot.path.str()) . ' | only'
180+
else
181+
return 'cd ' . fnameescape(getcwd())
182+
endif
183+
endfunction
184+
177185
" Automatic commands to manage the default session. {{{1
178186

179187
function! xolox#session#auto_load() " {{{2
@@ -277,7 +285,7 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
277285
let msg = "%s: The %s session at %s doesn't exist!"
278286
call xolox#misc#msg#warn(msg, s:script, string(name), fnamemodify(path, ':~'))
279287
elseif a:bang == '!' || !s:session_is_locked(path, 'OpenSession')
280-
let oldcwd = getcwd()
288+
let oldcwd = s:nerdtree_persist()
281289
call xolox#session#close_cmd(a:bang, 1)
282290
let s:oldcwd = oldcwd
283291
call s:lock_session(path)
@@ -375,9 +383,9 @@ function! xolox#session#close_cmd(bang, silent) abort " {{{2
375383
execute 'silent bdelete' bufnr
376384
endif
377385
endfor
378-
" Restore working directory from before :OpenSession.
386+
" Restore working directory (and NERDTree?) from before :OpenSession.
379387
if exists('s:oldcwd')
380-
execute 'cd' fnameescape(s:oldcwd)
388+
execute s:oldcwd
381389
unlet s:oldcwd
382390
endif
383391
unlet! s:session_is_dirty

plugin/session.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Author: Peter Odding
33
" Last Change: May 26, 2011
44
" URL: http://peterodding.com/code/vim/session/
5-
" Version: 1.4.3
5+
" Version: 1.4.4
66

77
" Support for automatic update using the GLVS plug-in.
88
" GetLatestVimScripts: 3150 1 :AutoInstall: session.zip

0 commit comments

Comments
 (0)