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.
This commit is contained in:
Martin Grenfell 2015-11-16 11:28:24 +00:00
parent 0b966aa23a
commit d36b793656
10 changed files with 42 additions and 42 deletions

View File

@ -142,7 +142,7 @@ endfunction
function! s:chRoot(node) function! s:chRoot(node)
call a:node.makeRoot() call a:node.makeRoot()
call b:NERDTree.render() call b:NERDTree.render()
call b:NERDTreeRoot.putCursorHere(0, 0) call b:NERDTree.root.putCursorHere(0, 0)
endfunction endfunction
" FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1 " FUNCTION: s:nerdtree#ui_glue#chRootCwd() {{{1
@ -289,7 +289,7 @@ function! s:findAndRevealPath()
endif endif
endif endif
call g:NERDTree.CursorToTreeWin() call g:NERDTree.CursorToTreeWin()
let node = b:NERDTreeRoot.reveal(p) let node = b:NERDTree.root.reveal(p)
call b:NERDTree.render() call b:NERDTree.render()
call node.putCursorHere(1,0) call node.putCursorHere(1,0)
@ -411,7 +411,7 @@ endfunction
" FUNCTION: s:jumpToRoot() {{{1 " FUNCTION: s:jumpToRoot() {{{1
" moves the cursor to the root node " moves the cursor to the root node
function! s:jumpToRoot() function! s:jumpToRoot()
call b:NERDTreeRoot.putCursorHere(1, 0) call b:NERDTree.root.putCursorHere(1, 0)
call b:NERDTree.ui.centerView() call b:NERDTree.ui.centerView()
endfunction endfunction
@ -524,7 +524,7 @@ endfunction
" will be reloaded. " will be reloaded.
function! s:refreshRoot() function! s:refreshRoot()
call nerdtree#echo("Refreshing the root node. This could take a while...") 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() call b:NERDTree.render()
redraw redraw
call nerdtree#echo("Refreshing the root node. This could take a while... DONE") 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 "keepState: 1 if the current root should be left open when the tree is
"re-rendered "re-rendered
function! nerdtree#ui_glue#upDir(keepState) 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 =~# '^[^/]..$' if cwd ==# "/" || cwd =~# '^[^/]..$'
call nerdtree#echo("already at top dir") call nerdtree#echo("already at top dir")
else else
if !a:keepState if !a:keepState
call b:NERDTreeRoot.close() call b:NERDTree.root.close()
endif endif
let oldRoot = b:NERDTreeRoot let oldRoot = b:NERDTree.root
if empty(b:NERDTreeRoot.parent) if empty(b:NERDTree.root.parent)
let path = b:NERDTreeRoot.path.getParent() let path = b:NERDTree.root.path.getParent()
let newRoot = g:NERDTreeDirNode.New(path) let newRoot = g:NERDTreeDirNode.New(path)
call newRoot.open() call newRoot.open()
call newRoot.transplantChild(b:NERDTreeRoot) call newRoot.transplantChild(b:NERDTree.root)
let b:NERDTreeRoot = newRoot let b:NERDTree.root = newRoot
else else
let b:NERDTreeRoot = b:NERDTreeRoot.parent let b:NERDTree.root = b:NERDTree.root.parent
endif endif
if g:NERDTreeChDirMode ==# 2 if g:NERDTreeChDirMode ==# 2
call b:NERDTreeRoot.path.changeToDir() call b:NERDTree.root.path.changeToDir()
endif endif
call b:NERDTree.render() call b:NERDTree.render()

View File

@ -945,7 +945,7 @@ Other examples: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'NERDTreeStatusline'* *'NERDTreeStatusline'*
Values: Any valid statusline setting. 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 Tells the script what to use as the |'statusline'| setting for NERD tree
windows. windows.

View File

@ -147,7 +147,7 @@ endfunction
" searchFromAbsoluteRoot: specifies whether we should search from the current " searchFromAbsoluteRoot: specifies whether we should search from the current
" tree root, or the highest cached node " tree root, or the highest cached node
function! s:Bookmark.getNode(searchFromAbsoluteRoot) 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) let targetNode = searchRoot.findNode(self.path)
if empty(targetNode) if empty(targetNode)
throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name

View File

@ -68,7 +68,7 @@ function! s:Creator.createTabTree(name)
call self._createTreeWin() call self._createTreeWin()
call self._createNERDTree(path, "tab") call self._createNERDTree(path, "tab")
call b:NERDTree.render() call b:NERDTree.render()
call b:NERDTreeRoot.putCursorHere(0, 0) call b:NERDTree.root.putCursorHere(0, 0)
call self._broadcastInitEvent() call self._broadcastInitEvent()
endfunction endfunction
@ -141,7 +141,7 @@ function! s:Creator.createMirror()
let i = 0 let i = 0
while i < len(treeBufNames) while i < len(treeBufNames)
let bufName = treeBufNames[i] 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 options[i+1 . '. ' . treeRoot.path.str() . ' (buf name: ' . bufName . ')'] = bufName
let i = i + 1 let i = i + 1
endwhile endwhile

View File

@ -73,7 +73,7 @@ endfunction
" Function: s:NERDTree.ExistsForBuffer() {{{1 " Function: s:NERDTree.ExistsForBuffer() {{{1
" Returns 1 if a nerd tree root exists in the current buffer " Returns 1 if a nerd tree root exists in the current buffer
function! s:NERDTree.ExistsForBuf() function! s:NERDTree.ExistsForBuf()
return exists("b:NERDTreeRoot") return exists("b:NERDTree")
endfunction endfunction
" Function: s:NERDTree.ExistsForTab() {{{1 " Function: s:NERDTree.ExistsForTab() {{{1

View File

@ -9,7 +9,7 @@ let g:NERDTreeDirNode = s:TreeDirNode
"FUNCTION: TreeDirNode.AbsoluteTreeRoot(){{{1 "FUNCTION: TreeDirNode.AbsoluteTreeRoot(){{{1
"class method that returns the highest cached ancestor of the current root "class method that returns the highest cached ancestor of the current root
function! s:TreeDirNode.AbsoluteTreeRoot() function! s:TreeDirNode.AbsoluteTreeRoot()
let currentNode = b:NERDTreeRoot let currentNode = b:NERDTree.root
while currentNode.parent != {} while currentNode.parent != {}
let currentNode = currentNode.parent let currentNode = currentNode.parent
endwhile endwhile

View File

@ -59,7 +59,7 @@ endfunction
function! s:TreeFileNode.copy(dest) function! s:TreeFileNode.copy(dest)
call self.path.copy(a:dest) call self.path.copy(a:dest)
let newPath = g:NERDTreePath.New(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) if !empty(parent)
call parent.refresh() call parent.refresh()
return parent.findNode(newPath) return parent.findNode(newPath)
@ -182,7 +182,7 @@ endfunction
"get the root node for this tab "get the root node for this tab
function! s:TreeFileNode.GetRootForTab() function! s:TreeFileNode.GetRootForTab()
if g:NERDTree.ExistsForTab() if g:NERDTree.ExistsForTab()
return getbufvar(t:NERDTreeBufName, 'NERDTreeRoot') return getbufvar(t:NERDTreeBufName, 'NERDTree').root
end end
return {} return {}
endfunction endfunction
@ -195,7 +195,7 @@ function! s:TreeFileNode.GetSelected()
if path ==# {} if path ==# {}
return {} return {}
endif endif
return b:NERDTreeRoot.findNode(path) return b:NERDTree.root.findNode(path)
catch /^NERDTree/ catch /^NERDTree/
return {} return {}
endtry endtry
@ -209,30 +209,30 @@ function! s:TreeFileNode.isVisible()
endfunction endfunction
"FUNCTION: TreeFileNode.isRoot() {{{1 "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() function! s:TreeFileNode.isRoot()
if !g:NERDTree.ExistsForBuf() if !g:NERDTree.ExistsForBuf()
throw "NERDTree.NoTreeError: No tree exists for the current buffer" throw "NERDTree.NoTreeError: No tree exists for the current buffer"
endif endif
return self.equals(b:NERDTreeRoot) return self.equals(b:NERDTree.root)
endfunction endfunction
"FUNCTION: TreeFileNode.makeRoot() {{{1 "FUNCTION: TreeFileNode.makeRoot() {{{1
"Make this node the root of the tree "Make this node the root of the tree
function! s:TreeFileNode.makeRoot() function! s:TreeFileNode.makeRoot()
if self.path.isDirectory if self.path.isDirectory
let b:NERDTreeRoot = self let b:NERDTree.root = self
else else
call self.cacheParent() call self.cacheParent()
let b:NERDTreeRoot = self.parent let b:NERDTree.root = self.parent
endif endif
call b:NERDTreeRoot.open() call b:NERDTree.root.open()
"change dir to the dir of the new root if instructed to "change dir to the dir of the new root if instructed to
if g:NERDTreeChDirMode ==# 2 if g:NERDTreeChDirMode ==# 2
exec "cd " . b:NERDTreeRoot.path.str({'format': 'Edit'}) exec "cd " . b:NERDTree.root.path.str({'format': 'Edit'})
endif endif
silent doautocmd User NERDTreeNewRoot silent doautocmd User NERDTreeNewRoot
@ -326,7 +326,7 @@ function! s:TreeFileNode.rename(newName)
call self.parent.removeChild(self) call self.parent.removeChild(self)
let parentPath = self.path.getParent() let parentPath = self.path.getParent()
let newParent = b:NERDTreeRoot.findNode(parentPath) let newParent = b:NERDTree.root.findNode(parentPath)
if newParent != {} if newParent != {}
call newParent.createChild(self.path, 1) call newParent.createChild(self.path, 1)

View File

@ -155,7 +155,7 @@ function! s:UI.getPath(ln)
"check to see if we have the root node "check to see if we have the root node
if a:ln == rootLine if a:ln == rootLine
return b:NERDTreeRoot.path return self.nerdtree.root.path
endif endif
if !g:NERDTreeDirArrows if !g:NERDTreeDirArrows
@ -166,7 +166,7 @@ function! s:UI.getPath(ln)
endif endif
if line ==# s:UI.UpDirLine() if line ==# s:UI.UpDirLine()
return b:NERDTreeRoot.path.getParent() return self.nerdtree.root.path.getParent()
endif endif
let indent = self._indentLevelFor(line) let indent = self._indentLevelFor(line)
@ -189,7 +189,7 @@ function! s:UI.getPath(ln)
"have we reached the top of the tree? "have we reached the top of the tree?
if lnum == rootLine if lnum == rootLine
let dir = b:NERDTreeRoot.path.str({'format': 'UI'}) . dir let dir = self.nerdtree.root.path.str({'format': 'UI'}) . dir
break break
endif endif
if curLineStripped =~# '/$' if curLineStripped =~# '/$'
@ -202,7 +202,7 @@ function! s:UI.getPath(ln)
endif endif
endif endif
endwhile endwhile
let curFile = b:NERDTreeRoot.path.drive . dir . curFile let curFile = self.nerdtree.root.path.drive . dir . curFile
let toReturn = g:NERDTreePath.New(curFile) let toReturn = g:NERDTreePath.New(curFile)
return toReturn return toReturn
endfunction endfunction
@ -218,7 +218,7 @@ function! s:UI.getLineNum(file_node)
let totalLines = line("$") let totalLines = line("$")
"the path components we have matched so far "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 "the index of the component we are searching for
let curPathComponent = 1 let curPathComponent = 1
@ -442,13 +442,13 @@ function! s:UI.render()
endif endif
"draw the header line "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 setline(line(".")+1, header)
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
"draw the tree "draw the tree
let old_o = @o let old_o = @o
let @o = b:NERDTreeRoot.renderToString() let @o = self.nerdtree.root.renderToString()
silent put o silent put o
let @o = old_o let @o = old_o
@ -504,7 +504,7 @@ endfunction
function! s:UI.toggleShowBookmarks() function! s:UI.toggleShowBookmarks()
let self._showBookmarks = !self._showBookmarks let self._showBookmarks = !self._showBookmarks
if self.getShowBookmarks() if self.getShowBookmarks()
call b:NERDTree.render() call self.nerdtree.render()
call g:NERDTree.CursorToBookmarkTable() call g:NERDTree.CursorToBookmarkTable()
else else
call self.renderViewSavingPosition() call self.renderViewSavingPosition()

View File

@ -105,11 +105,11 @@ function! NERDTreeAddNode()
try try
let newPath = g:NERDTreePath.Create(newNodeName) 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) let newTreeNode = g:NERDTreeFileNode.New(newPath)
if empty(parentNode) if empty(parentNode)
call b:NERDTreeRoot.refresh() call b:NERDTree.root.refresh()
call b:NERDTree.render() call b:NERDTree.render()
elseif parentNode.isOpen || !empty(parentNode.children) elseif parentNode.isOpen || !empty(parentNode.children)
call parentNode.addChild(newTreeNode, 1) call parentNode.addChild(newTreeNode, 1)
@ -245,7 +245,7 @@ function! NERDTreeCopyNode()
try try
let newNode = currentNode.copy(newNodePath) let newNode = currentNode.copy(newNodePath)
if empty(newNode) if empty(newNode)
call b:NERDTreeRoot.refresh() call b:NERDTree.root.refresh()
call b:NERDTree.render() call b:NERDTree.render()
else else
call NERDTreeRender() call NERDTreeRender()

View File

@ -83,8 +83,8 @@ if !exists('g:NERDTreeStatusline')
"the exists() crap here is a hack to stop vim spazzing out when "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 "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) "because it doesnt store b:NERDTree(its a b: var, and its a hash)
let g:NERDTreeStatusline = "%{exists('b:NERDTreeRoot')?b:NERDTreeRoot.path.str():''}" let g:NERDTreeStatusline = "%{exists('b:NERDTree')?b:NERDTree.root.path.str():''}"
endif endif
call s:initVariable("g:NERDTreeWinPos", "left") call s:initVariable("g:NERDTreeWinPos", "left")