use buffer level variables instead of tab lvl

This commit is contained in:
Martin Grenfell 2008-12-13 19:29:03 +13:00
parent 9aba1c17f6
commit b0297c5c91

View File

@ -129,7 +129,7 @@ call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U")
"SECTION: Script level variable declaration{{{2
let s:escape_chars = " \\`\|\"#%&,?()\*^<>"
let s:NERDTreeWinName = '_NERD_tree_'
let s:NERDTreeBufName = '_NERD_tree_'
let s:tree_wid = 2
let s:tree_markup_reg = '^[ `|]*[\-+~]'
@ -150,7 +150,7 @@ command! -n=1 -complete=customlist,s:completeBookmarks NERDTreeFromBookmark call
" SECTION: Auto commands {{{1
"============================================================
"Save the cursor position whenever we close the nerd tree
exec "autocmd BufWinLeave *". s:NERDTreeWinName ." call <SID>saveScreenState()"
exec "autocmd BufWinLeave *". s:NERDTreeBufName ." call <SID>saveScreenState()"
"cache bookmarks when vim loads
autocmd VimEnter * call s:Bookmark.CacheBookmarks(0)
@ -285,7 +285,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 ? s:TreeDirNode.AbsoluteTreeRoot() : t:NERDTreeRoot
let searchRoot = a:searchFromAbsoluteRoot ? s:TreeDirNode.AbsoluteTreeRoot() : b:NERDTreeRoot
let targetNode = searchRoot.findNode(self.path)
if empty(targetNode)
throw "NERDTree.BookmarkedNodeNotFound no node was found for bookmark: " . self.name
@ -458,7 +458,7 @@ endfunction
function! s:TreeFileNode.copy(dest)
call self.path.copy(a:dest)
let newPath = s:Path.New(a:dest)
let parent = t:NERDTreeRoot.findNode(newPath.getParent())
let parent = b:NERDTreeRoot.findNode(newPath.getParent())
if !empty(parent)
call parent.refresh()
endif
@ -571,29 +571,29 @@ endfunction
"FUNCTION: TreeFileNode.isRoot() {{{3
"returns 1 if this node is t:NERDTreeRoot
"returns 1 if this node is b:NERDTreeRoot
function! s:TreeFileNode.isRoot()
if !s:treeExistsForTab()
throw "NERDTree.TreeFileNode.IsRoot exception: No tree exists for the current tab"
endif
return self.equals(t:NERDTreeRoot)
return self.equals(b:NERDTreeRoot)
endfunction
"FUNCTION: TreeFileNode.makeRoot() {{{3
"Make this node the root of the tree
function! s:TreeFileNode.makeRoot()
if self.path.isDirectory
let t:NERDTreeRoot = self
let b:NERDTreeRoot = self
else
call self.cacheParent()
let t:NERDTreeRoot = self.parent
let b:NERDTreeRoot = self.parent
endif
call t:NERDTreeRoot.open()
call b:NERDTreeRoot.open()
"change dir to the dir of the new root if instructed to
if g:NERDTreeChDirMode == 2
exec "cd " . t:NERDTreeRoot.path.strForEditCmd()
exec "cd " . b:NERDTreeRoot.path.strForEditCmd()
endif
endfunction
"FUNCTION: TreeFileNode.New(path) {{{3
@ -625,7 +625,7 @@ function! s:TreeFileNode.rename(newName)
call self.parent.removeChild(self)
let parentPath = self.path.getPathTrunk()
let newParent = t:NERDTreeRoot.findNode(parentPath)
let newParent = b:NERDTreeRoot.findNode(parentPath)
if newParent != {}
call newParent.createChild(self.path, 1)
@ -652,7 +652,7 @@ let s:TreeDirNode = copy(s:TreeFileNode)
"FUNCTION: TreeDirNode.AbsoluteTreeRoot(){{{3
"class method that returns the highest cached ancestor of the current root
function! s:TreeDirNode.AbsoluteTreeRoot()
let currentNode = t:NERDTreeRoot
let currentNode = b:NERDTreeRoot
while currentNode.parent != {}
let currentNode = currentNode.parent
endwhile
@ -1342,7 +1342,7 @@ function! s:Path.ignore()
let lastPathComponent = self.getLastPathComponent(0)
"filter out the user specified paths to ignore
if t:NERDTreeIgnoreEnabled
if b:NERDTreeIgnoreEnabled
for i in g:NERDTreeIgnore
if lastPathComponent =~ i
return 1
@ -1351,11 +1351,11 @@ function! s:Path.ignore()
endif
"dont show hidden files unless instructed to
if t:NERDTreeShowHidden == 0 && lastPathComponent =~ '^\.'
if b:NERDTreeShowHidden == 0 && lastPathComponent =~ '^\.'
return 1
endif
if t:NERDTreeShowFiles == 0 && self.isDirectory == 0
if b:NERDTreeShowFiles == 0 && self.isDirectory == 0
return 1
endif
@ -1702,30 +1702,32 @@ function! s:initNerdTree(name)
exec 'cd ' . path.strForCd()
endif
let t:treeShowHelp = 0
let t:NERDTreeIgnoreEnabled = 1
let t:NERDTreeShowFiles = g:NERDTreeShowFiles
let t:NERDTreeShowHidden = g:NERDTreeShowHidden
let t:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks
if s:treeExistsForTab()
if s:isTreeOpen()
call s:closeTree()
endif
unlet t:NERDTreeRoot
unlet b:NERDTreeRoot
endif
let t:NERDTreeRoot = s:TreeDirNode.New(path)
call t:NERDTreeRoot.open()
let newRoot = s:TreeDirNode.New(path)
call newRoot.open()
call s:createTreeWin()
let b:treeShowHelp = 0
let b:NERDTreeIgnoreEnabled = 1
let b:NERDTreeShowFiles = g:NERDTreeShowFiles
let b:NERDTreeShowHidden = g:NERDTreeShowHidden
let b:NERDTreeShowBookmarks = g:NERDTreeShowBookmarks
let b:NERDTreeRoot = newRoot
call s:renderView()
call s:putCursorOnNode(t:NERDTreeRoot, 0, 0)
call s:putCursorOnNode(b:NERDTreeRoot, 0, 0)
endfunction
" Function: s:treeExistsForTab() {{{2
" Returns 1 if a nerd tree root exists in the current tab
function! s:treeExistsForTab()
return exists("t:NERDTreeRoot")
return exists("t:NERDTreeBufName")
endfunction
" SECTION: Public Functions {{{1
"============================================================
@ -1821,8 +1823,10 @@ function! s:createTreeWin()
let splitLocation = (g:NERDTreeWinPos == "top" || g:NERDTreeWinPos == "left") ? "topleft " : "botright "
let splitMode = s:shouldSplitVertically() ? "vertical " : ""
let splitSize = g:NERDTreeWinSize
let t:NERDTreeWinName = localtime() . s:NERDTreeWinName
let cmd = splitLocation . splitMode . splitSize . ' new ' . t:NERDTreeWinName
if !exists('t:NERDTreeBufName')
let t:NERDTreeBufName = localtime() . s:NERDTreeBufName
endif
let cmd = splitLocation . splitMode . splitSize . ' new ' . t:NERDTreeBufName
silent! execute cmd
setlocal winfixwidth
@ -1830,7 +1834,7 @@ function! s:createTreeWin()
"throwaway buffer options
setlocal noswapfile
setlocal buftype=nofile
setlocal bufhidden=delete
"setlocal bufhidden=delete
setlocal nowrap
setlocal foldcolumn=0
setlocal nobuflisted
@ -1935,7 +1939,7 @@ endfunction
"prints out the quick help
function! s:dumpHelp()
let old_h = @h
if t:treeShowHelp == 1
if b:treeShowHelp == 1
let @h= "\" NERD tree (" . s:NERD_tree_version . ") quickhelp~\n"
let @h=@h."\" ============================\n"
let @h=@h."\" File node mappings~\n"
@ -1993,10 +1997,10 @@ function! s:dumpHelp()
let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Tree filtering mappings~\n"
let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (t:NERDTreeShowHidden ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (t:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (t:NERDTreeShowFiles ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (t:NERDTreeShowBookmarks ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleHidden .": hidden files (" . (b:NERDTreeShowHidden ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleFilters .": file filters (" . (b:NERDTreeIgnoreEnabled ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleFiles .": files (" . (b:NERDTreeShowFiles ? "on" : "off") . ")\n"
let @h=@h."\" ". g:NERDTreeMapToggleBookmarks .": bookmarks (" . (b:NERDTreeShowBookmarks ? "on" : "off") . ")\n"
let @h=@h."\"\n\" ----------------------------\n"
let @h=@h."\" Other mappings~\n"
@ -2059,7 +2063,7 @@ function! s:findNodeLineNumber(treenode)
let totalLines = line("$")
"the path components we have matched so far
let pathcomponents = [substitute(t:NERDTreeRoot.path.str(0), '/ *$', '', '')]
let pathcomponents = [substitute(b:NERDTreeRoot.path.str(0), '/ *$', '', '')]
"the index of the component we are searching for
let curPathComponent = 1
@ -2137,7 +2141,7 @@ function! s:getPath(ln)
"check to see if we have the root node
if line =~ '^\/'
return t:NERDTreeRoot.path
return b:NERDTreeRoot.path
endif
" in case called from outside the tree
@ -2146,7 +2150,7 @@ function! s:getPath(ln)
endif
if line == s:tree_up_dir_line
return t:NERDTreeRoot.path.getParent()
return b:NERDTreeRoot.path.getParent()
endif
let indent = s:indentLevelFor(line)
@ -2183,7 +2187,7 @@ function! s:getPath(ln)
endif
endif
endwhile
let curFile = t:NERDTreeRoot.path.drive . dir . curFile
let curFile = b:NERDTreeRoot.path.drive . dir . curFile
let toReturn = s:Path.New(curFile)
return toReturn
endfunction
@ -2223,7 +2227,7 @@ function! s:getSelectedNode()
if path == {}
return {}
endif
return t:NERDTreeRoot.findNode(path)
return b:NERDTreeRoot.findNode(path)
catch /^NERDTree/
return {}
endtry
@ -2231,8 +2235,8 @@ endfunction
"FUNCTION: s:getTreeWinNum() {{{2
"gets the nerd tree window number for this tab
function! s:getTreeWinNum()
if exists("t:NERDTreeWinName")
return bufwinnr(t:NERDTreeWinName)
if exists("t:NERDTreeBufName")
return bufwinnr(t:NERDTreeBufName)
else
return -1
endif
@ -2455,7 +2459,7 @@ function! s:openNodeSplit(treenode)
"resize the tree window if no other window was open before
if onlyOneWin
let size = exists("t:NERDTreeOldWindowSize") ? t:NERDTreeOldWindowSize : g:NERDTreeWinSize
let size = exists("b:NERDTreeOldWindowSize") ? b:NERDTreeOldWindowSize : g:NERDTreeWinSize
exec(there)
exec("silent ". splitMode ." resize ". size)
wincmd p
@ -2484,7 +2488,7 @@ endfunction
"FUNCTION: s:putCursorOnBookmarkTable(){{{2
"Places the cursor at the top of the bookmarks table
function! s:putCursorOnBookmarkTable()
if !t:NERDTreeShowBookmarks
if !b:NERDTreeShowBookmarks
throw "NERDTree.IllegalOperation exception: cant find bookmark table, bookmarks arent active"
endif
@ -2558,8 +2562,6 @@ endfunction
"
"Args:
function! s:renderView()
execute s:getTreeWinNum() . "wincmd w"
setlocal modifiable
"remember the top line of the buffer and the current line so we can
@ -2577,7 +2579,7 @@ function! s:renderView()
call setline(line(".")+1, "")
call cursor(line(".")+1, col("."))
if t:NERDTreeShowBookmarks
if b:NERDTreeShowBookmarks
call s:renderBookmarks()
endif
@ -2586,11 +2588,11 @@ function! s:renderView()
call cursor(line(".")+1, col("."))
"draw the header line
call setline(line(".")+1, t:NERDTreeRoot.path.str(0))
call setline(line(".")+1, b:NERDTreeRoot.path.str(0))
call cursor(line(".")+1, col("."))
"draw the tree
call s:drawTree(t:NERDTreeRoot, 0, 0, [], t:NERDTreeRoot.getChildCount() == 1)
call s:drawTree(b:NERDTreeRoot, 0, 0, [], b:NERDTreeRoot.getChildCount() == 1)
"delete the blank line at the top of the buffer
silent 1,1delete _
@ -2631,16 +2633,16 @@ endfunction
"
"Assumes the cursor is in the NERDTree window
function! s:restoreScreenState()
if !exists("t:NERDTreeOldTopLine") || !exists("t:NERDTreeOldPos") || !exists("t:NERDTreeOldWindowSize")
if !exists("b:NERDTreeOldTopLine") || !exists("b:NERDTreeOldPos") || !exists("b:NERDTreeOldWindowSize")
return
endif
exec("silent ". (s:shouldSplitVertically() ? "vertical" : "") ." resize ".t:NERDTreeOldWindowSize)
exec("silent ". (s:shouldSplitVertically() ? "vertical" : "") ." resize ".b:NERDTreeOldWindowSize)
let old_scrolloff=&scrolloff
let &scrolloff=0
call cursor(t:NERDTreeOldTopLine, 0)
call cursor(b:NERDTreeOldTopLine, 0)
normal! zt
call setpos(".", t:NERDTreeOldPos)
call setpos(".", b:NERDTreeOldPos)
let &scrolloff=old_scrolloff
endfunction
@ -2651,9 +2653,9 @@ function! s:saveScreenState()
let win = winnr()
try
call s:putCursorInTreeWin()
let t:NERDTreeOldPos = getpos(".")
let t:NERDTreeOldTopLine = line("w0")
let t:NERDTreeOldWindowSize = s:shouldSplitVertically() ? winwidth("") : winheight("")
let b:NERDTreeOldPos = getpos(".")
let b:NERDTreeOldTopLine = line("w0")
let b:NERDTreeOldWindowSize = s:shouldSplitVertically() ? winwidth("") : winheight("")
exec win . "wincmd w"
catch /NERDTree.view.InvalidOperation/
endtry
@ -2803,8 +2805,6 @@ function! s:toggle(dir)
if s:treeExistsForTab()
if !s:isTreeOpen()
call s:createTreeWin()
call s:renderView()
call s:restoreScreenState()
else
call s:closeTree()
@ -2985,7 +2985,7 @@ function! s:chRoot()
call treenode.makeRoot()
call s:renderView()
call s:putCursorOnNode(t:NERDTreeRoot, 0, 0)
call s:putCursorOnNode(b:NERDTreeRoot, 0, 0)
endfunction
" FUNCTION: s:clearBookmarks(bookmarks) {{{2
@ -3153,7 +3153,7 @@ endfunction
" FUNCTION: s:displayHelp() {{{2
" toggles the help display
function! s:displayHelp()
let t:treeShowHelp = t:treeShowHelp ? 0 : 1
let b:treeShowHelp = b:treeShowHelp ? 0 : 1
call s:renderView()
call s:centerView()
endfunction
@ -3215,7 +3215,7 @@ function! s:insertNewNode()
try
let newPath = s:Path.Create(newNodeName)
let parentNode = t:NERDTreeRoot.findNode(newPath.getPathTrunk())
let parentNode = b:NERDTreeRoot.findNode(newPath.getPathTrunk())
let newTreeNode = s:TreeFileNode.New(newPath)
if parentNode.isOpen || !empty(parentNode.children)
@ -3259,7 +3259,7 @@ endfunction
" FUNCTION: s:jumpToRoot() {{{2
" moves the cursor to the root node
function! s:jumpToRoot()
call s:putCursorOnNode(t:NERDTreeRoot, 1, 0)
call s:putCursorOnNode(b:NERDTreeRoot, 1, 0)
call s:centerView()
endfunction
@ -3401,7 +3401,7 @@ endfunction
" will be reloaded.
function! s:refreshRoot()
call s:echo("Refreshing the root node. This could take a while...")
call t:NERDTreeRoot.refresh()
call b:NERDTreeRoot.refresh()
call s:renderView()
redraw
call s:echo("Refreshing the root node. This could take a while... DONE")
@ -3501,7 +3501,7 @@ endfunction
" FUNCTION: s:toggleIgnoreFilter() {{{2
" toggles the use of the NERDTreeIgnore option
function! s:toggleIgnoreFilter()
let t:NERDTreeIgnoreEnabled = !t:NERDTreeIgnoreEnabled
let b:NERDTreeIgnoreEnabled = !b:NERDTreeIgnoreEnabled
call s:renderViewSavingPosition()
call s:centerView()
endfunction
@ -3509,8 +3509,8 @@ endfunction
" FUNCTION: s:toggleShowBookmarks() {{{2
" toggles the display of bookmarks
function! s:toggleShowBookmarks()
let t:NERDTreeShowBookmarks = !t:NERDTreeShowBookmarks
if t:NERDTreeShowBookmarks
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
if b:NERDTreeShowBookmarks
call s:renderView()
call s:putCursorOnBookmarkTable()
else
@ -3521,7 +3521,7 @@ endfunction
" FUNCTION: s:toggleShowFiles() {{{2
" toggles the display of hidden files
function! s:toggleShowFiles()
let t:NERDTreeShowFiles = !t:NERDTreeShowFiles
let b:NERDTreeShowFiles = !b:NERDTreeShowFiles
call s:renderViewSavingPosition()
call s:centerView()
endfunction
@ -3529,7 +3529,7 @@ endfunction
" FUNCTION: s:toggleShowHidden() {{{2
" toggles the display of hidden files
function! s:toggleShowHidden()
let t:NERDTreeShowHidden = !t:NERDTreeShowHidden
let b:NERDTreeShowHidden = !b:NERDTreeShowHidden
call s:renderViewSavingPosition()
call s:centerView()
endfunction
@ -3541,24 +3541,24 @@ endfunction
"keepState: 1 if the current root should be left open when the tree is
"re-rendered
function! s:upDir(keepState)
let cwd = t:NERDTreeRoot.path.str(0)
let cwd = b:NERDTreeRoot.path.str(0)
if cwd == "/" || cwd =~ '^[^/]..$'
call s:echo("already at top dir")
else
if !a:keepState
call t:NERDTreeRoot.close()
call b:NERDTreeRoot.close()
endif
let oldRoot = t:NERDTreeRoot
let oldRoot = b:NERDTreeRoot
if empty(t:NERDTreeRoot.parent)
let path = t:NERDTreeRoot.path.getPathTrunk()
if empty(b:NERDTreeRoot.parent)
let path = b:NERDTreeRoot.path.getPathTrunk()
let newRoot = s:TreeDirNode.New(path)
call newRoot.open()
call newRoot.transplantChild(t:NERDTreeRoot)
let t:NERDTreeRoot = newRoot
call newRoot.transplantChild(b:NERDTreeRoot)
let b:NERDTreeRoot = newRoot
else
let t:NERDTreeRoot = t:NERDTreeRoot.parent
let b:NERDTreeRoot = b:NERDTreeRoot.parent
endif