Skip to content
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

Add NERDTreeRefreshRoot command #897

Merged
merged 2 commits into from Oct 16, 2018

Conversation

wgfm
Copy link
Contributor

@wgfm wgfm commented Oct 12, 2018

Implements #727

@PhilRunninger
Copy link
Member

@wgfm, thanks for the contribution. It appears you have some more work to do. While it works when NERDTree is the active window, if my active window is anything else, I get this error.

NERDTree: Refreshing the root node. This could take a while...
Error detected while processing function <SNR>47_refreshRoot:
line    2:
E121: Undefined variable: b:NERDTree
line    3:
E121: Undefined variable: b:NERDTree
NERDTree: Refreshing the root node. This could take a while... DONE
NERDTree: Refreshing the root node. This could take a while...
NERDTree: Refreshing the root node. This could take a while... DONE

Also, make sure the help file include a description of the new command.

@wgfm
Copy link
Contributor Author

wgfm commented Oct 12, 2018

Ah, I see. It's because NERDTree is scoped to that particular buffer. I do not want to be invasive, nor do I have extensive knowledge of the codebase and vimscript. Would you have some pointers for a possible approach I could take?

I'd also understand if you don't have the time to guide me through this.

@PhilRunninger
Copy link
Member

You've chosen a complicated program with which to learn vimscript, but that's OK. The plugin is written in a style that mimics object-oriented programming as much as a scripting language can. There is a global "object" you can access from any window. It is g:NERDTree, and the code is in lib/nerdtree/nerdtree.vim. I suggest you write a new function there that does the following:

  1. Return if NERDTree is not open.
  2. Get the current window.
  3. Switch to the NERDTree window.
  4. Refresh it.
  5. Switch back to the original window.

The pieces are all there in that file's other functions and in the s:refreshRoot() function of ui_glue.vim.

Don't forget to change your command! ... NERDTreeRefreshRoot... to call your new function.

Give it another try. This shouldn't be too hard, and if you get stuck, I can help you out.

@wgfm
Copy link
Contributor Author

wgfm commented Oct 14, 2018

I've added a g:NERDTree.RefreshRoot() function. There's a couple of things I'm not really sure about.

  1. Should the redraw happen in ui_glue?
  2. Should we call the new function from s:refreshRoot() to reduce duplication?
  3. The doc entry is quite short, but then again, there's not a lot going on that would require longer documentation.

Copy link
Member

@PhilRunninger PhilRunninger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this another thought after your questions, and there is a better way to do this, which directly answers your second question. Fortunately, it's a simple change from what you have now. The new function you wrote in lib/nerdtree/nerdtree.vim can be moved to ui_glue.vim to replace the s:refreshRoot() function. Just keep the nerdtree#echo() function calls, and use g:NERDTree instead of s:NERDTree.

@@ -79,7 +79,7 @@ function! s:NERDTree.CursorToBookmarkTable()
endif

if g:NERDTreeMinimalUI
return cursor(1, 2)
return cursor(1, 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave this at 4 space indent.

@wgfm wgfm force-pushed the wh_refresh_root_#727 branch 2 times, most recently from ae65acf to 0e8fbcc Compare October 16, 2018 06:04
@wgfm
Copy link
Contributor Author

wgfm commented Oct 16, 2018

I have implemented the requested changes. Now, there are two unnecessary window switches happening when the root is refreshed while NERDTree is the current buffer.

Copy link
Member

@PhilRunninger PhilRunninger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wgfm, one more change, and this will be ready to merge. Regarding your comment about switching windows unnecessarily, the way you've written it is fine. The wincmd w command recognizes that the cursor is already in the specified window, and won't do anything.

autoload/nerdtree/ui_glue.vim Show resolved Hide resolved
@PhilRunninger PhilRunninger merged commit 5381197 into preservim:master Oct 16, 2018
@wgfm
Copy link
Contributor Author

wgfm commented Oct 16, 2018

@PhilRunninger, thank you so much for your time. Much appreciated!

@wgfm wgfm deleted the wh_refresh_root_#727 branch October 16, 2018 15:37
@thinker3
Copy link

I use vim ., but now press R can't refresh root, I have to checkout 6b6cadf : 2018-10-10 22:19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants