Compare commits

...

10 Commits
4.0.0 ... 4.1.0

Author SHA1 Message Date
marty
153041ac93 switch to version 4.1.0 2009-12-01 22:20:53 +13:00
marty
68cb5fc2eb update changelog and credits 2009-12-01 22:19:43 +13:00
marty
ee7aafb135 bugfix: paths were incorrectly escaped in win32 for :e and :cd 2009-11-24 21:34:41 +13:00
marty
b047d7f312 put the open-in-new-tab logic in the models, make NERDTreeQuitOnOpen effect T and t 2009-11-24 00:11:02 +13:00
marty
1537d42706 move s:getSelectedBookmark in to the Bookmark model 2009-11-24 00:10:44 +13:00
marty
4b566f153f add NERDTreeFind command and handling code 2009-11-22 19:29:16 +13:00
marty
f34986d30f move the path string truncation into Path#str() 2009-11-22 18:25:23 +13:00
marty
a713a86f06 truncate the root line if its too long
and by "too long" i mean wider than the nerdtree window
2009-11-05 13:49:36 +13:00
marty
08bc9870bc bugfix: escape filenames for ":edit"ing 2009-10-10 12:30:28 +13:00
marty
94e085f1a2 really fix the window state restoring 2009-10-09 21:27:48 +13:00
2 changed files with 198 additions and 52 deletions

View File

@@ -128,6 +128,11 @@ The following features and functionality are provided by the NERD tree:
:NERDTreeClose *:NERDTreeClose* :NERDTreeClose *:NERDTreeClose*
Close the NERD tree in this tab. Close the NERD tree in this tab.
:NERDTreeFind *:NERDTreeFind*
Find the current file in the tree. If no tree exists for the current tab,
or the file is not under the current root, then initialize a new tree where
the root is the directory of the current file.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2. Bookmarks *NERDTreeBookmarks* 2.2. Bookmarks *NERDTreeBookmarks*
@@ -803,7 +808,7 @@ Values: 0 or 1.
Default: 0 Default: 0
If set to 1, the NERD tree window will close after opening a file with the If set to 1, the NERD tree window will close after opening a file with the
|NERDTree-o| or |NERDTree-i| mappings. |NERDTree-o|, |NERDTree-i|, |NERDTree-t| and |NERDTree-T| mappings.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'NERDTreeShowBookmarks'* *'NERDTreeShowBookmarks'*
@@ -1075,6 +1080,21 @@ The latest dev versions are on github
============================================================================== ==============================================================================
6. Changelog *NERDTreeChangelog* 6. Changelog *NERDTreeChangelog*
4.1.0
features:
- NERDTreeFind to reveal the node for the current buffer in the tree,
see |NERDTreeFind|. This effectively merges the FindInNERDTree plugin (by
Doug McInnes) into the script.
- make NERDTreeQuitOnOpen apply to the t/T keymaps too. Thanks to Stefan
Ritter and Rémi Prévost.
- truncate the root node if wider than the tree window. Thanks to Victor
Gonzalez.
bugfixes:
- really fix window state restoring
- fix some win32 path escaping issues. Thanks to Stephan Baumeister, Ricky,
jfilip1024, and Chris Chambers
4.0.0 4.0.0
- add a new programmable menu system (see :help NERDTreeMenu). - add a new programmable menu system (see :help NERDTreeMenu).
- add new APIs to add menus/menu-items to the menu system as well as - add new APIs to add menus/menu-items to the menu system as well as
@@ -1186,6 +1206,14 @@ just downloaded pr0n instead.
Curtis Harvey Curtis Harvey
Guillaume Duranceau Guillaume Duranceau
Richard Hart (hates) Richard Hart (hates)
Doug McInnes
Stefan Ritter
Rémi Prévost
Victor Gonzalez
Stephan Baumeister
Ricky
jfilip1024
Chris Chambers
============================================================================== ==============================================================================
8. License *NERDTreeLicense* 8. License *NERDTreeLicense*

View File

@@ -2,7 +2,7 @@
" File: NERD_tree.vim " File: NERD_tree.vim
" Description: vim global plugin that provides a nice tree explorer " Description: vim global plugin that provides a nice tree explorer
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com> " Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
" Last Change: 9 October, 2009 " Last Change: 1 December, 2009
" License: This program is free software. It comes without any warranty, " License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute " to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You " it and/or modify it under the terms of the Do What The Fuck You
@@ -10,7 +10,7 @@
" See http://sam.zoy.org/wtfpl/COPYING for more details. " See http://sam.zoy.org/wtfpl/COPYING for more details.
" "
" ============================================================================ " ============================================================================
let s:NERD_tree_version = '4.0.0' let s:NERD_tree_version = '4.1.0'
" SECTION: Script init stuff {{{1 " SECTION: Script init stuff {{{1
"============================================================ "============================================================
@@ -139,7 +139,11 @@ call s:initVariable("g:NERDTreeMapUpdir", "u")
call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U") call s:initVariable("g:NERDTreeMapUpdirKeepOpen", "U")
"SECTION: Script level variable declaration{{{2 "SECTION: Script level variable declaration{{{2
let s:escape_chars = " \\`\|\"#%&,?()\*^<>" if s:running_windows
let s:escape_chars = " `\|\"#%&,?()\*^<>"
else
let s:escape_chars = " \\`\|\"#%&,?()\*^<>"
endif
let s:NERDTreeBufName = 'NERD_tree_' let s:NERDTreeBufName = 'NERD_tree_'
let s:tree_wid = 2 let s:tree_wid = 2
@@ -157,6 +161,7 @@ command! -n=? -complete=dir -bar NERDTreeToggle :call s:toggle('<args>')
command! -n=0 -bar NERDTreeClose :call s:closeTreeIfOpen() command! -n=0 -bar NERDTreeClose :call s:closeTreeIfOpen()
command! -n=1 -complete=customlist,s:completeBookmarks -bar NERDTreeFromBookmark call s:initNerdTree('<args>') command! -n=1 -complete=customlist,s:completeBookmarks -bar NERDTreeFromBookmark call s:initNerdTree('<args>')
command! -n=0 -bar NERDTreeMirror call s:initNerdTreeMirror() command! -n=0 -bar NERDTreeMirror call s:initNerdTreeMirror()
command! -n=0 -bar NERDTreeFind call s:findAndRevealPath()
" SECTION: Auto commands {{{1 " SECTION: Auto commands {{{1
"============================================================ "============================================================
augroup NERDTree augroup NERDTree
@@ -332,6 +337,21 @@ function! s:Bookmark.GetNodeForName(name, searchFromAbsoluteRoot)
let bookmark = s:Bookmark.BookmarkFor(a:name) let bookmark = s:Bookmark.BookmarkFor(a:name)
return bookmark.getNode(a:searchFromAbsoluteRoot) return bookmark.getNode(a:searchFromAbsoluteRoot)
endfunction endfunction
" FUNCTION: Bookmark.GetSelected() {{{3
" returns the Bookmark the cursor is over, or {}
function! s:Bookmark.GetSelected()
let line = getline(".")
let name = substitute(line, '^>\(.\{-}\) .\+$', '\1', '')
if name != line
try
return s:Bookmark.BookmarkFor(name)
catch /^NERDTree.BookmarkNotFoundError/
return {}
endtry
endif
return {}
endfunction
" Function: Bookmark.InvalidBookmarks() {{{3 " Function: Bookmark.InvalidBookmarks() {{{3
" Class method to get all invalid bookmark strings read from the bookmarks " Class method to get all invalid bookmark strings read from the bookmarks
" file " file
@@ -361,6 +381,21 @@ function! s:Bookmark.New(name, path)
let newBookmark.path = a:path let newBookmark.path = a:path
return newBookmark return newBookmark
endfunction endfunction
" FUNCTION: Bookmark.openInNewTab(options) {{{3
" Create a new bookmark object with the given name and path object
function! s:Bookmark.openInNewTab(options)
let currentTab = tabpagenr()
if self.path.isDirectory
tabnew
call s:initNerdTree(self.name)
else
exec "tabedit " . bookmark.path.str({'format': 'Edit'})
endif
if has_key(a:options, 'stayInCurrentTab')
exec "tabnext " . currentTab
endif
endfunction
" Function: Bookmark.setPath(path) {{{3 " Function: Bookmark.setPath(path) {{{3
" makes this bookmark point to the given path " makes this bookmark point to the given path
function! s:Bookmark.setPath(path) function! s:Bookmark.setPath(path)
@@ -981,11 +1016,19 @@ function! s:TreeFileNode.getLineNum()
return -1 return -1
endfunction endfunction
"FUNCTION: TreeFileNode.GetRootForTab(){{{3
"get the root node for this tab
function! s:TreeFileNode.GetRootForTab()
if s:treeExistsForTab()
return getbufvar(t:NERDTreeBufName, 'NERDTreeRoot')
end
return {}
endfunction
"FUNCTION: TreeFileNode.GetRootLineNum(){{{3 "FUNCTION: TreeFileNode.GetRootLineNum(){{{3
"gets the line number of the root node "gets the line number of the root node
function! s:TreeFileNode.GetRootLineNum() function! s:TreeFileNode.GetRootLineNum()
let rootLine = 1 let rootLine = 1
while getline(rootLine) !~ '^/' while getline(rootLine) !~ '^\(/\|<\)'
let rootLine = rootLine + 1 let rootLine = rootLine + 1
endwhile endwhile
return rootLine return rootLine
@@ -1177,6 +1220,21 @@ function! s:TreeFileNode.openVSplit()
exec("silent vertical resize ". winwidth) exec("silent vertical resize ". winwidth)
call s:exec('wincmd p') call s:exec('wincmd p')
endfunction endfunction
"FUNCTION: TreeFileNode.openInNewTab(options) {{{3
function! s:TreeFileNode.openInNewTab(options)
let currentTab = tabpagenr()
if !has_key(a:options, 'keepTreeOpen')
call s:closeTreeIfQuitOnOpen()
endif
exec "tabedit " . self.path.str({'format': 'Edit'})
if has_key(a:options, 'stayInCurrentTab') && a:options['stayInCurrentTab']
exec "tabnext " . currentTab
endif
endfunction
"FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{3 "FUNCTION: TreeFileNode.putCursorHere(isJump, recurseUpward){{{3
"Places the cursor on the line number this node is rendered on "Places the cursor on the line number this node is rendered on
" "
@@ -1606,6 +1664,22 @@ function! s:TreeDirNode.openExplorer()
exec ("silent edit " . self.path.str({'format': 'Edit'})) exec ("silent edit " . self.path.str({'format': 'Edit'}))
endif endif
endfunction endfunction
"FUNCTION: TreeDirNode.openInNewTab(options) {{{3
unlet s:TreeDirNode.openInNewTab
function! s:TreeDirNode.openInNewTab(options)
let currentTab = tabpagenr()
if !has_key(a:options, 'keepTreeOpen') || !a:options['keepTreeOpen']
call s:closeTreeIfQuitOnOpen()
endif
tabnew
call s:initNerdTree(self.path.str())
if has_key(a:options, 'stayInCurrentTab') && a:options['stayInCurrentTab']
exec "tabnext " . currentTab
endif
endfunction
"FUNCTION: TreeDirNode.openRecursively() {{{3 "FUNCTION: TreeDirNode.openRecursively() {{{3
"Opens this treenode and all of its children whose paths arent 'ignored' "Opens this treenode and all of its children whose paths arent 'ignored'
"because of the file filters. "because of the file filters.
@@ -1690,6 +1764,31 @@ function! s:TreeDirNode.refresh()
endif endif
endfunction endfunction
"FUNCTION: TreeDirNode.reveal(path) {{{3
"reveal the given path, i.e. cache and open all treenodes needed to display it
"in the UI
function! s:TreeDirNode.reveal(path)
if !a:path.isUnder(self.path)
throw "NERDTree.InvalidArgumentsError: " . a:path.str() . " should be under " . self.path.str()
endif
call self.open()
if self.path.equals(a:path.getParent())
let n = self.findNode(a:path)
call s:renderView()
call n.putCursorHere(1,0)
return
endif
let p = a:path
while !p.getParent().equals(self.path)
let p = p.getParent()
endwhile
let n = self.findNode(p)
call n.reveal(a:path)
endfunction
"FUNCTION: TreeDirNode.removeChild(treenode) {{{3 "FUNCTION: TreeDirNode.removeChild(treenode) {{{3
" "
"Removes the given treenode from this nodes set of children "Removes the given treenode from this nodes set of children
@@ -2079,6 +2178,20 @@ function! s:Path.ignore()
return 0 return 0
endfunction endfunction
"FUNCTION: Path.isUnder(path) {{{3
"return 1 if this path is somewhere under the given path in the filesystem.
"
"a:path should be a dir
function! s:Path.isUnder(path)
if a:path.isDirectory == 0
return 0
endif
let this = self.str()
let that = a:path.str()
return stridx(this, that . s:Path.Slash()) == 0
endfunction
"FUNCTION: Path.JoinPathStrings(...) {{{3 "FUNCTION: Path.JoinPathStrings(...) {{{3
function! s:Path.JoinPathStrings(...) function! s:Path.JoinPathStrings(...)
let components = [] let components = []
@@ -2208,16 +2321,18 @@ endfunction
"The dict may have the following keys: "The dict may have the following keys:
" 'format' " 'format'
" 'escape' " 'escape'
" 'truncateTo'
" "
"The 'format' key may have a value of: "The 'format' key may have a value of:
" 'Cd' - a string to be used with the :cd command " 'Cd' - a string to be used with the :cd command
" 'Edit' - a string to be used with :e :sp :new :tabedit etc " 'Edit' - a string to be used with :e :sp :new :tabedit etc
" 'UI' - a string used in the NERD tree UI " 'UI' - a string used in the NERD tree UI
" "
"If not specified, a generic unix style path string will be returned
"
"The 'escape' key, if specified will cause the output to be escaped with "The 'escape' key, if specified will cause the output to be escaped with
"shellescape() "shellescape()
"
"The 'truncateTo' key causes the resulting string to be truncated to the value
"'truncateTo' maps to. A '<' char will be prepended.
function! s:Path.str(...) function! s:Path.str(...)
let options = a:0 ? a:1 : {} let options = a:0 ? a:1 : {}
let toReturn = "" let toReturn = ""
@@ -2237,6 +2352,13 @@ function! s:Path.str(...)
let toReturn = shellescape(toReturn) let toReturn = shellescape(toReturn)
endif endif
if has_key(options, 'truncateTo')
let limit = options['truncateTo']
if len(toReturn) > limit
let toReturn = "<" . strpart(toReturn, len(toReturn) - limit + 1)
endif
endif
return toReturn return toReturn
endfunction endfunction
@@ -2268,6 +2390,8 @@ function! s:Path._strForEdit()
let cwd = tolower(getcwd()) let cwd = tolower(getcwd())
endif endif
let p = escape(p, s:escape_chars)
let cwd = cwd . s:Path.Slash() let cwd = cwd . s:Path.Slash()
"return a relative path if we can "return a relative path if we can
@@ -2394,6 +2518,29 @@ function! s:exec(cmd)
exec a:cmd exec a:cmd
let &ei = old_ei let &ei = old_ei
endfunction endfunction
" FUNCTION: s:findAndRevealPath() {{{2
function! s:findAndRevealPath()
try
let p = s:Path.New(expand("%"))
catch /^NERDTree.InvalidArgumentsError/
call s:echo("no file for the current buffer")
return
endtry
if !s:treeExistsForTab()
call s:initNerdTree(p.getParent().str())
else
if !p.isUnder(s:TreeFileNode.GetRootForTab().path)
call s:initNerdTree(p.getParent().str())
else
if !s:isTreeOpen()
call s:toggle("")
endif
endif
endif
call s:putCursorInTreeWin()
call b:NERDTreeRoot.reveal(p)
endfunction
"FUNCTION: s:initNerdTree(name) {{{2 "FUNCTION: s:initNerdTree(name) {{{2
"Initialise the nerd tree for this tab. The tree will start in either the "Initialise the nerd tree for this tab. The tree will start in either the
"given directory, or the directory associated with the given bookmark "given directory, or the directory associated with the given bookmark
@@ -2896,8 +3043,10 @@ endfunction
function! s:getPath(ln) function! s:getPath(ln)
let line = getline(a:ln) let line = getline(a:ln)
let rootLine = s:TreeFileNode.GetRootLineNum()
"check to see if we have the root node "check to see if we have the root node
if line =~ '^\/' if a:ln == rootLine
return b:NERDTreeRoot.path return b:NERDTreeRoot.path
endif endif
@@ -2921,7 +3070,6 @@ function! s:getPath(ln)
let curFile = substitute(curFile, '/\?$', '/', "") let curFile = substitute(curFile, '/\?$', '/', "")
endif endif
let dir = "" let dir = ""
let lnum = a:ln let lnum = a:ln
while lnum > 0 while lnum > 0
@@ -2930,8 +3078,8 @@ function! s:getPath(ln)
let curLineStripped = s:stripMarkupFromLine(curLine, 1) let curLineStripped = s:stripMarkupFromLine(curLine, 1)
"have we reached the top of the tree? "have we reached the top of the tree?
if curLine =~ '^/' if lnum == rootLine
let dir = substitute (curLine, ' *$', "", "") . dir let dir = b:NERDTreeRoot.path.str({'format': 'UI'}) . dir
break break
endif endif
if curLineStripped =~ '/$' if curLineStripped =~ '/$'
@@ -2949,21 +3097,6 @@ function! s:getPath(ln)
return toReturn return toReturn
endfunction endfunction
"FUNCTION: s:getSelectedBookmark() {{{2
"returns the bookmark the cursor is over in the bookmarks table or {}
function! s:getSelectedBookmark()
let line = getline(".")
let name = substitute(line, '^>\(.\{-}\) .\+$', '\1', '')
if name != line
try
return s:Bookmark.BookmarkFor(name)
catch /^NERDTree.BookmarkNotFoundError/
return {}
endtry
endif
return {}
endfunction
"FUNCTION: s:getTreeWinNum() {{{2 "FUNCTION: s:getTreeWinNum() {{{2
"gets the nerd tree window number for this tab "gets the nerd tree window number for this tab
function! s:getTreeWinNum() function! s:getTreeWinNum()
@@ -3130,7 +3263,8 @@ function! s:renderView()
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
"draw the header line "draw the header line
call setline(line(".")+1, b:NERDTreeRoot.path.str({'format': 'UI'})) let header = b:NERDTreeRoot.path.str({'format': 'UI', 'truncateTo': winwidth(0)})
call setline(line(".")+1, header)
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
"draw the tree "draw the tree
@@ -3351,10 +3485,10 @@ function! s:toggle(dir)
if s:treeExistsForTab() if s:treeExistsForTab()
if !s:isTreeOpen() if !s:isTreeOpen()
call s:createTreeWin() call s:createTreeWin()
call s:restoreScreenState()
if !&hidden if !&hidden
call s:renderView() call s:renderView()
endif endif
call s:restoreScreenState()
else else
call s:closeTree() call s:closeTree()
endif endif
@@ -3379,7 +3513,7 @@ function! s:activateNode(forceKeepWindowOpen)
if treenode != {} if treenode != {}
call treenode.activate(a:forceKeepWindowOpen) call treenode.activate(a:forceKeepWindowOpen)
else else
let bookmark = s:getSelectedBookmark() let bookmark = s:Bookmark.GetSelected()
if !empty(bookmark) if !empty(bookmark)
call bookmark.activate() call bookmark.activate()
endif endif
@@ -3589,7 +3723,7 @@ endfunction
" FUNCTION: s:deleteBookmark() {{{2 " FUNCTION: s:deleteBookmark() {{{2
" if the cursor is on a bookmark, prompt to delete " if the cursor is on a bookmark, prompt to delete
function! s:deleteBookmark() function! s:deleteBookmark()
let bookmark = s:getSelectedBookmark() let bookmark = s:Bookmark.GetSelected()
if bookmark ==# {} if bookmark ==# {}
call s:echo("Put the cursor on a bookmark") call s:echo("Put the cursor on a bookmark")
return return
@@ -3746,29 +3880,13 @@ endfunction
" stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim " stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim
" will go to the tab where the new file is opened " will go to the tab where the new file is opened
function! s:openInNewTab(stayCurrentTab) function! s:openInNewTab(stayCurrentTab)
let currentTab = tabpagenr() let target = s:TreeFileNode.GetSelected()
if target == {}
let treenode = s:TreeFileNode.GetSelected() let target = s:Bookmark.GetSelected()
if treenode != {}
if treenode.path.isDirectory
tabnew
call s:initNerdTree(treenode.path.str())
else
exec "tabedit " . treenode.path.str({'format': 'Edit'})
endif
else
let bookmark = s:getSelectedBookmark()
if bookmark != {}
if bookmark.path.isDirectory
tabnew
call s:initNerdTree(bookmark.name)
else
exec "tabedit " . bookmark.path.str({'format': 'Edit'})
endif
endif
endif endif
if a:stayCurrentTab
exec "tabnext " . currentTab if target != {}
call target.openInNewTab({'stayInCurrentTab': a:stayCurrentTab})
endif endif
endfunction endfunction