@@ -109,9 +109,8 @@ function! xolox#session#save_state(commands) " {{{2
109
109
endtry
110
110
endfunction
111
111
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.
115
114
let tabpage = tabpagenr ()
116
115
let window = winnr ()
117
116
try
@@ -174,6 +173,15 @@ function! s:jump_to_window(session, tabpage, window)
174
173
call add (a: session , a: window . ' wincmd w' )
175
174
endfunction
176
175
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
+
177
185
" Automatic commands to manage the default session. {{{1
178
186
179
187
function ! xolox#session#auto_load () " {{{2
@@ -277,7 +285,7 @@ function! xolox#session#open_cmd(name, bang) abort " {{{2
277
285
let msg = " %s: The %s session at %s doesn't exist!"
278
286
call xolox#misc#msg#warn (msg, s: script , string (name), fnamemodify (path , ' :~' ))
279
287
elseif a: bang == ' !' || ! s: session_is_locked (path , ' OpenSession' )
280
- let oldcwd = getcwd ()
288
+ let oldcwd = s: nerdtree_persist ()
281
289
call xolox#session#close_cmd (a: bang , 1 )
282
290
let s: oldcwd = oldcwd
283
291
call s: lock_session (path )
@@ -375,9 +383,9 @@ function! xolox#session#close_cmd(bang, silent) abort " {{{2
375
383
execute ' silent bdelete' bufnr
376
384
endif
377
385
endfor
378
- " Restore working directory from before :OpenSession.
386
+ " Restore working directory (and NERDTree?) from before :OpenSession.
379
387
if exists (' s:oldcwd' )
380
- execute ' cd ' fnameescape ( s: oldcwd)
388
+ execute s: oldcwd
381
389
unlet s: oldcwd
382
390
endif
383
391
unlet ! s: session_is_dirty
0 commit comments