-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NERDTreeCWD: reset CWD if changed by NERDTreeFocus #878
Conversation
When the user has `'autochdir'` turned on, opening a new NERDTree will cause the current working directory to change. To prevent this happening, remember the CWD and reset it if NERDTreeFocus caused it to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good start. However, I don't see any care taken to work around the possibility of a window-local current working directory. You would need to use the :lcd
command in this case.
It's an edge case. But I think it deserves some investigation.
plugin/NERD_tree.vim
Outdated
call NERDTreeFocus() | ||
if l:cwd != getcwd() | ||
exec 'cd '.l:cwd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should wrap l:cwd
with fnameescape()
here.
If you read the documentation at function! NERDTreeCWD()
let l:cwdPath = g:NERDTreePath.New(getcwd())
call NERDTreeFocus()
if b:NERDTree.root.path.equals(l:cwdPath)
return
endif
let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree)
call b:NERDTree.changeRoot(l:newRoot)
endfunction This matches the documentation perfectly, reproduced below:
I assert that changing the working directory in any way is not in the scope of this command! Also, the documentation may be improved a tad...
EDIT: You can extend this idea to change the working directory of the NERDTree window (if it needs a local one) or to change the global working directory. The important idea here is that the details are saved before we leave the initial context. EDIT: It should also be pointed out that changing the working directory is pointless when |
I thought about it more last night... I think my above comment and suggested function definition is right on the money. Even in the documentation for
I just don't think the setting is working the way the user thinks it should. |
@lifecrisis , ready for a 2nd review. |
Hey @PhilRunninger. Updates look great! Just added a couple of commits on top of yours. If you're okay with everything, then so am I. Let me know if this is good or if you think of anything else. |
Looks good. I hadn't considered the |
Fixes #855.
When the user has
'autochdir'
turned on, opening a new NERDTree willcause the current working directory to change. To prevent this
happening, remember the CWD and reset it if NERDTreeFocus caused it to
change.