From d36b7936566f9913a0fa3925ba57214f17f302a3 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Mon, 16 Nov 2015 11:28:24 +0000 Subject: [PATCH] dont use b:NERDTreeRoot internally, but leave the var there for compat Use b:NERDTree.root instead. I will eventually remove b:NERDTreeRoot altogether - but this will break some other plugins so leave it for now. --- autoload/nerdtree/ui_glue.vim | 26 +++++++++++++------------- doc/NERD_tree.txt | 2 +- lib/nerdtree/bookmark.vim | 2 +- lib/nerdtree/creator.vim | 4 ++-- lib/nerdtree/nerdtree.vim | 2 +- lib/nerdtree/tree_dir_node.vim | 2 +- lib/nerdtree/tree_file_node.vim | 20 ++++++++++---------- lib/nerdtree/ui.vim | 16 ++++++++-------- nerdtree_plugin/fs_menu.vim | 6 +++--- plugin/NERD_tree.vim | 4 ++-- 10 files changed, 42 insertions(+), 42 deletions(-) diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim index 5d18044..23edfe7 100644 --- a/autoload/nerdtree/ui_glue.vim +++ b/autoload/nerdtree/ui_glue.vim @@ -142,7 +142,7 @@ endfunction function! s:chRoot(node) call a:node.makeRoot() call b:NERDTree.render() - call b:NERDTreeRoot.putCursorHere(0, 0) + call b:NERDTree.root.putCursorHere(0, 0) endfunction " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1 @@ -289,7 +289,7 @@ function! s:findAndRevealPath() endif endif call g:NERDTree.CursorToTreeWin() - let node = b:NERDTreeRoot.reveal(p) + let node = b:NERDTree.root.reveal(p) call b:NERDTree.render() call node.putCursorHere(1,0) @@ -411,7 +411,7 @@ endfunction " FUNCTION: s:jumpToRoot() {{{1 " moves the cursor to the root node function! s:jumpToRoot() - call b:NERDTreeRoot.putCursorHere(1, 0) + call b:NERDTree.root.putCursorHere(1, 0) call b:NERDTree.ui.centerView() endfunction @@ -524,7 +524,7 @@ endfunction " will be reloaded. function! s:refreshRoot() call nerdtree#echo("Refreshing the root node. This could take a while...") - call b:NERDTreeRoot.refresh() + call b:NERDTree.root.refresh() call b:NERDTree.render() redraw call nerdtree#echo("Refreshing the root node. This could take a while... DONE") @@ -604,28 +604,28 @@ endfunction "keepState: 1 if the current root should be left open when the tree is "re-rendered function! nerdtree#ui_glue#upDir(keepState) - let cwd = b:NERDTreeRoot.path.str({'format': 'UI'}) + let cwd = b:NERDTree.root.path.str({'format': 'UI'}) if cwd ==# "/" || cwd =~# '^[^/]..$' call nerdtree#echo("already at top dir") else if !a:keepState - call b:NERDTreeRoot.close() + call b:NERDTree.root.close() endif - let oldRoot = b:NERDTreeRoot + let oldRoot = b:NERDTree.root - if empty(b:NERDTreeRoot.parent) - let path = b:NERDTreeRoot.path.getParent() + if empty(b:NERDTree.root.parent) + let path = b:NERDTree.root.path.getParent() let newRoot = g:NERDTreeDirNode.New(path) call newRoot.open() - call newRoot.transplantChild(b:NERDTreeRoot) - let b:NERDTreeRoot = newRoot + call newRoot.transplantChild(b:NERDTree.root) + let b:NERDTree.root = newRoot else - let b:NERDTreeRoot = b:NERDTreeRoot.parent + let b:NERDTree.root = b:NERDTree.root.parent endif if g:NERDTreeChDirMode ==# 2 - call b:NERDTreeRoot.path.changeToDir() + call b:NERDTree.root.path.changeToDir() endif call b:NERDTree.render() diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt index caab120..ccc60b5 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERD_tree.txt @@ -945,7 +945,7 @@ Other examples: > ------------------------------------------------------------------------------ *'NERDTreeStatusline'* Values: Any valid statusline setting. -Default: %{b:NERDTreeRoot.path.strForOS(0)} +Default: %{b:NERDTree.root.path.strForOS(0)} Tells the script what to use as the |'statusline'| setting for NERD tree windows. diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index 91648d2..1b49f02 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -147,7 +147,7 @@ endfunction " searchFromAbsoluteRoot: specifies whether we should search from the current " tree root, or the highest cached node function! s:Bookmark.getNode(searchFromAbsoluteRoot) - let searchRoot = a:searchFromAbsoluteRoot ? g:NERDTreeDirNode.AbsoluteTreeRoot() : b:NERDTreeRoot + let searchRoot = a:searchFromAbsoluteRoot ? g:NERDTreeDirNode.AbsoluteTreeRoot() : b:NERDTree.root let targetNode = searchRoot.findNode(self.path) if empty(targetNode) throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim index 87d1b1b..61f204f 100644 --- a/lib/nerdtree/creator.vim +++ b/lib/nerdtree/creator.vim @@ -68,7 +68,7 @@ function! s:Creator.createTabTree(name) call self._createTreeWin() call self._createNERDTree(path, "tab") call b:NERDTree.render() - call b:NERDTreeRoot.putCursorHere(0, 0) + call b:NERDTree.root.putCursorHere(0, 0) call self._broadcastInitEvent() endfunction @@ -141,7 +141,7 @@ function! s:Creator.createMirror() let i = 0 while i < len(treeBufNames) let bufName = treeBufNames[i] - let treeRoot = getbufvar(bufName, "NERDTreeRoot") + let treeRoot = getbufvar(bufName, "NERDTree").root let options[i+1 . '. ' . treeRoot.path.str() . ' (buf name: ' . bufName . ')'] = bufName let i = i + 1 endwhile diff --git a/lib/nerdtree/nerdtree.vim b/lib/nerdtree/nerdtree.vim index 938c5f8..83468ca 100644 --- a/lib/nerdtree/nerdtree.vim +++ b/lib/nerdtree/nerdtree.vim @@ -73,7 +73,7 @@ endfunction " Function: s:NERDTree.ExistsForBuffer() {{{1 " Returns 1 if a nerd tree root exists in the current buffer function! s:NERDTree.ExistsForBuf() - return exists("b:NERDTreeRoot") + return exists("b:NERDTree") endfunction " Function: s:NERDTree.ExistsForTab() {{{1 diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 0fb4016..e1e82cb 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -9,7 +9,7 @@ let g:NERDTreeDirNode = s:TreeDirNode "FUNCTION: TreeDirNode.AbsoluteTreeRoot(){{{1 "class method that returns the highest cached ancestor of the current root function! s:TreeDirNode.AbsoluteTreeRoot() - let currentNode = b:NERDTreeRoot + let currentNode = b:NERDTree.root while currentNode.parent != {} let currentNode = currentNode.parent endwhile diff --git a/lib/nerdtree/tree_file_node.vim b/lib/nerdtree/tree_file_node.vim index a3fe98f..b2a536e 100644 --- a/lib/nerdtree/tree_file_node.vim +++ b/lib/nerdtree/tree_file_node.vim @@ -59,7 +59,7 @@ endfunction function! s:TreeFileNode.copy(dest) call self.path.copy(a:dest) let newPath = g:NERDTreePath.New(a:dest) - let parent = b:NERDTreeRoot.findNode(newPath.getParent()) + let parent = b:NERDTree.root.findNode(newPath.getParent()) if !empty(parent) call parent.refresh() return parent.findNode(newPath) @@ -182,7 +182,7 @@ endfunction "get the root node for this tab function! s:TreeFileNode.GetRootForTab() if g:NERDTree.ExistsForTab() - return getbufvar(t:NERDTreeBufName, 'NERDTreeRoot') + return getbufvar(t:NERDTreeBufName, 'NERDTree').root end return {} endfunction @@ -195,7 +195,7 @@ function! s:TreeFileNode.GetSelected() if path ==# {} return {} endif - return b:NERDTreeRoot.findNode(path) + return b:NERDTree.root.findNode(path) catch /^NERDTree/ return {} endtry @@ -209,30 +209,30 @@ function! s:TreeFileNode.isVisible() endfunction "FUNCTION: TreeFileNode.isRoot() {{{1 -"returns 1 if this node is b:NERDTreeRoot +"returns 1 if this node is b:NERDTree.root function! s:TreeFileNode.isRoot() if !g:NERDTree.ExistsForBuf() throw "NERDTree.NoTreeError: No tree exists for the current buffer" endif - return self.equals(b:NERDTreeRoot) + return self.equals(b:NERDTree.root) endfunction "FUNCTION: TreeFileNode.makeRoot() {{{1 "Make this node the root of the tree function! s:TreeFileNode.makeRoot() if self.path.isDirectory - let b:NERDTreeRoot = self + let b:NERDTree.root = self else call self.cacheParent() - let b:NERDTreeRoot = self.parent + let b:NERDTree.root = self.parent endif - call b:NERDTreeRoot.open() + call b:NERDTree.root.open() "change dir to the dir of the new root if instructed to if g:NERDTreeChDirMode ==# 2 - exec "cd " . b:NERDTreeRoot.path.str({'format': 'Edit'}) + exec "cd " . b:NERDTree.root.path.str({'format': 'Edit'}) endif silent doautocmd User NERDTreeNewRoot @@ -326,7 +326,7 @@ function! s:TreeFileNode.rename(newName) call self.parent.removeChild(self) let parentPath = self.path.getParent() - let newParent = b:NERDTreeRoot.findNode(parentPath) + let newParent = b:NERDTree.root.findNode(parentPath) if newParent != {} call newParent.createChild(self.path, 1) diff --git a/lib/nerdtree/ui.vim b/lib/nerdtree/ui.vim index f83647c..40c014e 100644 --- a/lib/nerdtree/ui.vim +++ b/lib/nerdtree/ui.vim @@ -155,7 +155,7 @@ function! s:UI.getPath(ln) "check to see if we have the root node if a:ln == rootLine - return b:NERDTreeRoot.path + return self.nerdtree.root.path endif if !g:NERDTreeDirArrows @@ -166,7 +166,7 @@ function! s:UI.getPath(ln) endif if line ==# s:UI.UpDirLine() - return b:NERDTreeRoot.path.getParent() + return self.nerdtree.root.path.getParent() endif let indent = self._indentLevelFor(line) @@ -189,7 +189,7 @@ function! s:UI.getPath(ln) "have we reached the top of the tree? if lnum == rootLine - let dir = b:NERDTreeRoot.path.str({'format': 'UI'}) . dir + let dir = self.nerdtree.root.path.str({'format': 'UI'}) . dir break endif if curLineStripped =~# '/$' @@ -202,7 +202,7 @@ function! s:UI.getPath(ln) endif endif endwhile - let curFile = b:NERDTreeRoot.path.drive . dir . curFile + let curFile = self.nerdtree.root.path.drive . dir . curFile let toReturn = g:NERDTreePath.New(curFile) return toReturn endfunction @@ -218,7 +218,7 @@ function! s:UI.getLineNum(file_node) let totalLines = line("$") "the path components we have matched so far - let pathcomponents = [substitute(b:NERDTreeRoot.path.str({'format': 'UI'}), '/ *$', '', '')] + let pathcomponents = [substitute(self.nerdtree.root.path.str({'format': 'UI'}), '/ *$', '', '')] "the index of the component we are searching for let curPathComponent = 1 @@ -442,13 +442,13 @@ function! s:UI.render() endif "draw the header line - let header = b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)}) + let header = self.nerdtree.root.path.str({'format': 'UI', 'truncateTo': winwidth(0)}) call setline(line(".")+1, header) call cursor(line(".")+1, col(".")) "draw the tree let old_o = @o - let @o = b:NERDTreeRoot.renderToString() + let @o = self.nerdtree.root.renderToString() silent put o let @o = old_o @@ -504,7 +504,7 @@ endfunction function! s:UI.toggleShowBookmarks() let self._showBookmarks = !self._showBookmarks if self.getShowBookmarks() - call b:NERDTree.render() + call self.nerdtree.render() call g:NERDTree.CursorToBookmarkTable() else call self.renderViewSavingPosition() diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim index 2f401a6..315a789 100644 --- a/nerdtree_plugin/fs_menu.vim +++ b/nerdtree_plugin/fs_menu.vim @@ -105,11 +105,11 @@ function! NERDTreeAddNode() try let newPath = g:NERDTreePath.Create(newNodeName) - let parentNode = b:NERDTreeRoot.findNode(newPath.getParent()) + let parentNode = b:NERDTree.root.findNode(newPath.getParent()) let newTreeNode = g:NERDTreeFileNode.New(newPath) if empty(parentNode) - call b:NERDTreeRoot.refresh() + call b:NERDTree.root.refresh() call b:NERDTree.render() elseif parentNode.isOpen || !empty(parentNode.children) call parentNode.addChild(newTreeNode, 1) @@ -245,7 +245,7 @@ function! NERDTreeCopyNode() try let newNode = currentNode.copy(newNodePath) if empty(newNode) - call b:NERDTreeRoot.refresh() + call b:NERDTree.root.refresh() call b:NERDTree.render() else call NERDTreeRender() diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 42a3b1e..515bef9 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -83,8 +83,8 @@ if !exists('g:NERDTreeStatusline') "the exists() crap here is a hack to stop vim spazzing out when "loading a session that was created with an open nerd tree. It spazzes - "because it doesnt store b:NERDTreeRoot (its a b: var, and its a hash) - let g:NERDTreeStatusline = "%{exists('b:NERDTreeRoot')?b:NERDTreeRoot.path.str():''}" + "because it doesnt store b:NERDTree(its a b: var, and its a hash) + let g:NERDTreeStatusline = "%{exists('b:NERDTree')?b:NERDTree.root.path.str():''}" endif call s:initVariable("g:NERDTreeWinPos", "left")