From 18071f599955f6720170d9daa6835a663a6bbaf0 Mon Sep 17 00:00:00 2001 From: "Phil Runninger (mac)" Date: Wed, 22 Aug 2018 17:01:08 -0400 Subject: [PATCH 1/6] NERDTreeCWD: reset CWD if changed by NERDTreeFocus 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. --- plugin/NERD_tree.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 71d719a..f8700d5 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -202,7 +202,11 @@ function! NERDTreeFocus() endfunction function! NERDTreeCWD() + let l:cwd = getcwd() call NERDTreeFocus() + if l:cwd != getcwd() + exec 'cd '.l:cwd + endif call nerdtree#ui_glue#chRootCwd() endfunction From c726ec7318f1cbb756744333c05445d751804e80 Mon Sep 17 00:00:00 2001 From: "Phil Runninger (mac)" Date: Mon, 10 Sep 2018 06:57:39 -0400 Subject: [PATCH 2/6] Implement PR review comments. --- doc/NERDTree.txt | 4 ++-- plugin/NERD_tree.vim | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/NERDTree.txt b/doc/NERDTree.txt index a83c4e1..1cb9856 100644 --- a/doc/NERDTree.txt +++ b/doc/NERDTree.txt @@ -142,8 +142,8 @@ The following features and functionality are provided by the NERD tree: current tab does not exist, a new one will be initialized. :NERDTreeCWD *:NERDTreeCWD* - Change tree root to current directory. If no NERD tree exists for this - tab, a new tree will be opened. + Change the NERDTree root to the current working directory. If no NERDTree + exists for this tab, a new one is opened. ------------------------------------------------------------------------------ 2.2. Bookmarks *NERDTreeBookmarks* diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index f8700d5..93d299e 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -202,12 +202,15 @@ function! NERDTreeFocus() endfunction function! NERDTreeCWD() - let l:cwd = getcwd() + let l:cwdPath = g:NERDTreePath.New(getcwd()) call NERDTreeFocus() - if l:cwd != getcwd() - exec 'cd '.l:cwd + + if b:NERDTree.root.path.equals(l:cwdPath) + return endif - call nerdtree#ui_glue#chRootCwd() + + let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree) + call b:NERDTree.changeRoot(l:newRoot) endfunction function! NERDTreeAddPathFilter(callback) From 7c8c811f00f9e8f792a88a271f7f79ab0bdd7e85 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 10 Sep 2018 08:33:10 -0400 Subject: [PATCH 3/6] Edit the help file --- doc/NERDTree.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/NERDTree.txt b/doc/NERDTree.txt index 1cb9856..278eb6c 100644 --- a/doc/NERDTree.txt +++ b/doc/NERDTree.txt @@ -142,8 +142,8 @@ The following features and functionality are provided by the NERD tree: current tab does not exist, a new one will be initialized. :NERDTreeCWD *:NERDTreeCWD* - Change the NERDTree root to the current working directory. If no NERDTree - exists for this tab, a new one is opened. + Change the NERDTree root to the current working directory. If no + NERDTree exists for this tab, a new one is opened. ------------------------------------------------------------------------------ 2.2. Bookmarks *NERDTreeBookmarks* @@ -522,7 +522,7 @@ Default key: cd Map option: NERDTreeMapChdir Applies to: files and directories. -Change vims current working directory to that of the selected node. +Change Vim's current working directory to that of the selected node. ------------------------------------------------------------------------------ *NERDTree-CD* @@ -530,7 +530,7 @@ Default key: CD Map option: NERDTreeMapCWD Applies to: no restrictions. -Change tree root to vims current working directory. +Change the NERDTree root to Vim's current working directory. ------------------------------------------------------------------------------ *NERDTree-I* From 7e00a9971e16ccf88362ecf0d52fcd31c31582f2 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 10 Sep 2018 08:46:42 -0400 Subject: [PATCH 4/6] Check for error; remove code duplication --- autoload/nerdtree/ui_glue.vim | 13 ++----------- plugin/NERD_tree.vim | 9 ++++++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 6ba9ee6..36e71ec 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -142,18 +142,9 @@ function! s:chRoot(node) endfunction " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1 -" changes the current root to CWD +" Change the NERDTree root to match the current working directory. function! nerdtree#ui_glue#chRootCwd() - try - let cwd = g:NERDTreePath.New(getcwd()) - catch /^NERDTree.InvalidArgumentsError/ - call nerdtree#echo("current directory does not exist.") - return - endtry - if cwd.str() == g:NERDTreeFileNode.GetRootForTab().path.str() - return - endif - call s:chRoot(g:NERDTreeDirNode.New(cwd, b:NERDTree)) + NERDTreeCWD endfunction " FUNCTION: nnerdtree#ui_glue#clearBookmarks(bookmarks) {{{1 diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 93d299e..b29a306 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -202,7 +202,14 @@ function! NERDTreeFocus() endfunction function! NERDTreeCWD() - let l:cwdPath = g:NERDTreePath.New(getcwd()) + + try + let l:cwdPath = g:NERDTreePath.New(getcwd()) + catch /^NERDTree.InvalidArgumentsError/ + call nerdtree#echoWarning('current directory does not exist') + return + endtry + call NERDTreeFocus() if b:NERDTree.root.path.equals(l:cwdPath) From 5442d5e04ad3c43d05f4d74b34d8ec2b9eb47fb8 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 10 Sep 2018 08:52:43 -0400 Subject: [PATCH 5/6] Put cursor in first column --- plugin/NERD_tree.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index b29a306..74ca60d 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -218,6 +218,7 @@ function! NERDTreeCWD() let l:newRoot = g:NERDTreeFileNode.New(l:cwdPath, b:NERDTree) call b:NERDTree.changeRoot(l:newRoot) + normal! ^ endfunction function! NERDTreeAddPathFilter(callback) From 2cd4331b7837a16daa12858a32cf85fc49366683 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Mon, 10 Sep 2018 09:00:05 -0400 Subject: [PATCH 6/6] Check for unknown current working directory --- plugin/NERD_tree.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 74ca60d..2abd248 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -203,6 +203,11 @@ endfunction function! NERDTreeCWD() + if empty(getcwd()) + call nerdtree#echoWarning('current directory does not exist') + return + endif + try let l:cwdPath = g:NERDTreePath.New(getcwd()) catch /^NERDTree.InvalidArgumentsError/