Compare commits

..

27 Commits

Author SHA1 Message Date
Martin Grenfell
0620b91efa switch version to 2.13.0 2008-07-20 22:34:48 +12:00
Martin Grenfell
ea4d4ff80d fix to changelog 2008-07-20 22:33:59 +12:00
Martin Grenfell
45c33fe0f6 update changelog and credits 2008-07-20 11:28:26 +12:00
Martin Grenfell
fe249e20b9 tell the user how many files couldnt be loaded 2008-07-20 01:06:00 +12:00
Martin Grenfell
e819e13a5d check for FIFO files when initializing path objects
calling filereadable() on a FIFO file never terminates so we have to
check for them
2008-07-20 00:50:47 +12:00
Martin Grenfell
5c95fbda65 improve invalid bookmarks handling
invalid bookmarks now placed after a blank line at the bottom of the
bookmarks file

if invalid bookmarks are detected, an error is outputted which directs
the user to :help NERDTreeInvalidBookmarks, which had been added to the
help file in this commit
2008-07-16 22:46:46 +12:00
Martin Grenfell
3e217115bc fix a bug with improper use of bufwinnr function
add a '^' and '$' to the end of the file matching pattern so it cant get
confused by buffer names that happen to be a substring of buffer we are
comparing against
2008-07-16 18:37:52 +12:00
Martin Grenfell
5d564fdbcf bugfix for the mouse handling function
previously the mouse handling function was not passing the needed
argument to the ActivateNode function
2008-07-16 18:23:17 +12:00
Martin Grenfell
8184b964bc dont delete invalid bookmarks
now if invalid bookmarks are detected, the offending lines are moved to
the bottom of the bookmarks file.

if the user tries to activate a bookmark that has become invalid after
it was read, that bookmark will be removed from the cache and put at the
bottom of the bookmarks file
2008-07-15 23:22:36 +12:00
Martin Grenfell
0daeebc0eb Revert "implement copying nodes for windows"
This reverts commit 21601d9c3d.

Ok, so that copying command doesnt work for windows... it doesnt do
directories properly.
2008-07-14 11:19:56 +12:00
Martin Grenfell
5939fdb140 add s:ValidateBookmark() 2008-07-13 21:03:33 +12:00
Martin Grenfell
9dd850b672 refactored the bookmark not found exception code 2008-07-13 21:02:59 +12:00
Martin Grenfell
21601d9c3d implement copying nodes for windows 2008-07-13 20:23:48 +12:00
Martin Grenfell
332a1baedd ensure bookmarks exist before opening them 2008-07-13 16:38:52 +12:00
Martin Grenfell
e8aadb77b8 reposition a method in the file 2008-07-13 16:02:20 +12:00
Martin Grenfell
31c1faea32 make NERDTreeChDir default to 0
we dont need it to default to 1 anymore as that was a hack for windows,
but now that we handle windows paths properly we dont need it
2008-07-13 15:06:57 +12:00
Martin Grenfell
818a53003e write bookmarks file after deleting a bookmark 2008-07-13 14:13:58 +12:00
Martin Grenfell
78419f858c delete a paths bookmarks when delete the path 2008-07-13 14:08:06 +12:00
Martin Grenfell
b1d10a12fa refresh new parent node after a move operation 2008-07-13 14:03:12 +12:00
Martin Grenfell
f404cdd54b update bookmarks when moving via filesystem menu 2008-07-13 13:43:43 +12:00
Martin Grenfell
c463234452 fix caching bug for s:oPath.BookmarkNames() 2008-07-13 13:35:30 +12:00
Martin Grenfell
b1020ad9c8 remove some unused code 2008-07-13 11:39:43 +12:00
Martin Grenfell
0ad0d195e5 make NERDTreeQuitOnOpen option work with g<tab>/go 2008-07-11 21:17:29 +12:00
Martin Grenfell
43bf05c42e jump to the bookmarks table after opening it
when the user hits B and opens the bookmarks table, stick the cursor at
the top of it
2008-07-07 21:08:02 +12:00
Martin Grenfell
236df49362 refactor the t/T mappings for bookmarks
this way feels cleaner
2008-07-07 20:43:11 +12:00
Martin Grenfell
bccd73c8f5 make t/T open a nerd tree rather than netrw
make the t/T on directory nodes open a fresh NERD tree for the selected
dir in a new tab, rather than a netrw.
2008-07-07 20:43:11 +12:00
Martin Grenfell
fd487dfa5c make t/T open a new tree in a new tab, not netrw
doesnt work for paths with some screwed up chars in them
2008-07-07 20:43:11 +12:00
2 changed files with 269 additions and 98 deletions

View File

@@ -25,6 +25,7 @@ CONTENTS *NERDTree-contents*
2.2 Bookmarks.........................|NERDTreeBookmarks|
2.2.1 The bookmark table..........|NERDTreeBookmarkTable|
2.2.2 Bookmark commands...........|NERDTreeBookmarkCommands|
2.2.3 Invalid bookmarks...........|NERDTreeInvalidBookmarks|
2.3 NERD tree mappings................|NERDTreeMappings|
2.4 The filesystem menu...............|NERDTreeFilesysMenu|
3.Options.................................|NERDTreeOptions|
@@ -158,8 +159,27 @@ Note that the following commands are only available in the NERD tree buffer.
:ClearAllBookmarks
Remove all bookmarks.
:ReadBookmarks
Re-read the bookmarks in the |NERDTreeBookmarksFile|.
See also |:NERDTree| and |:NERDTreeFromBookmark|.
------------------------------------------------------------------------------
2.2.3. Invalid Bookmarks *NERDTreeInvalidBookmarks*
If invalid bookmarks are detected, the script will issue an error message and
the invalid bookmarks will become unavailable for use.
These bookmarks will still be stored in the bookmarks file (see
|NERDTreeBookmarksFile|), down the bottom. There will always be a blank line
after the valid bookmarks but before the invalid ones.
Each line in the bookmarks file represents one bookmark. The proper format is:
<bookmark name><space><full path to the bookmark location>
After you have corrected any invalid bookmarks, either restart vim, or go
:ReadBookmarks from the NERD tree window.
------------------------------------------------------------------------------
2.3. NERD tree Mappings *NERDTreeMappings*
@@ -240,8 +260,8 @@ Default key: t
Map option: NERDTreeMapOpenInTab
Applies to: files and directories.
Opens the selected file in a new tab. If a directory is selected, a netrw is
opened in a new tab.
Opens the selected file in a new tab. If a directory is selected, a fresh
NERD Tree for that directory is opened in a new tab.
If a bookmark which points to a directory is selected, open a NERD tree for
that directory in a new tab. If the bookmark points to a file, open that file
@@ -648,7 +668,7 @@ account. The above nodes would then be sorted like this: >
*NERDTreeChDirMode*
Values: 0, 1 or 2.
Default: 1.
Default: 0.
Use this option to tell the script when (if at all) to change the current
working directory (CWD) for vim.
@@ -667,11 +687,6 @@ the CWD is changed whenever the tree root is changed. For example, if the CWD
is /home/marty/foobar and you make the node for /home/marty/foobar/baz the new
root then the CWD will become /home/marty/foobar/baz.
Authors note: at work i have this option set to 1 because i have a giant ctags
file in the root dir of my project. This way i can initialise the NERD tree
with the root dir of my project and always have ctags available to me --- no
matter where i go with the NERD tree.
------------------------------------------------------------------------------
*NERDTreeHighlightCursorline*
Values: 0 or 1.
@@ -874,6 +889,28 @@ fridge for later ;)
==============================================================================
7. Changelog *NERDTreeChangelog*
2.13.0
- make NERDTreeChDir option default to 0 (i.e. never change vims current
working dir by default)
- when moving/deleting nodes with the filesystem menu, move/delete any
associated bookmarks
- make the t/T on directory nodes open a fresh NERD tree for the selected
dir in a new tab, rather than a netrw.
- place the cursor at the top of the bookmarks table when opening it with B
- make NERDTreeQuitOnOpen option work with the g<tab> and go mappings,
thanks to Maxim Kim for the bug report
- change how invalid bookmarks are handled. Now they are not deleted. If a
bookmark is malformed (in the bookmarks file) or points to an
invalid/nonexisting location then print an error and place the offending
bookmarks at the bottom of the bookmarks file. See :help
|NERDTreeInvalidBookmarks| for info. Thanks to Zhang Shuhan for the
suggestion and the testing.
- fix a bug with the 'o' mapping that occurred when opening a new buffer
for a file whose name was a substring of an already open file. Thanks to
Charlton Wang for the report.
- stop the script from going into an infinite loop when it tries to cache
a named pipe. Thanks to Charlton Wang for the report.
2.12.0
- added a UI for bookmarks. See :help NERDTreeBookmarkTable for details.
Thanks to Zhang Shuhan for testing and bug reports.
@@ -1148,7 +1185,7 @@ NERD tree window optional.
Thanks to Zhang Shuhan for all of his emails and testing to help improve the
NERD tree path handling. Thanks also for suggesting the bookmarks gui, and for
testing and making suggestions and bugreports.
testing and his many suggestions and bugreports about bookmarks.
Thanks to Cory Echols for sending a patch to add the :NERDTreeClose command and
set the NERD tree buffers filetype to 'nerdtree'
@@ -1160,6 +1197,13 @@ Thanks to Yuan Jiang for suggesting the "o" mapping shouldnt clobber "special"
windows, like taglist.
Thanks to Matan Nassau for the patch to add the NERDTreeQuitOnOpen option.
Thanks to Maxim Kim for reporting a bug with g<tab> and go mappings when
NERDTreeQuitOnOpen was set.
Thanks to Charlton Wang for reporting bugs with the 'o' mapping and with
handling named pipes.
==============================================================================
9. License *NERDTreeLicense*

View File

@@ -2,7 +2,7 @@
" File: NERD_tree.vim
" Description: vim global plugin that provides a nice tree explorer
" Maintainer: Martin Grenfell <martin_grenfell at msn dot com>
" Last Change: 5 July, 2008
" Last Change: 20 July, 2008
" License: This program is free software. It comes without any warranty,
" 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
@@ -10,7 +10,7 @@
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
" ============================================================================
let s:NERD_tree_version = '2.12.0'
let s:NERD_tree_version = '2.13.0'
" SECTION: Script init stuff {{{1
"============================================================
@@ -45,7 +45,7 @@ call s:InitVariable("g:NERDChristmasTree", 1)
call s:InitVariable("g:NERDTreeAutoCenter", 1)
call s:InitVariable("g:NERDTreeAutoCenterThreshold", 3)
call s:InitVariable("g:NERDTreeCaseSensitiveSort", 0)
call s:InitVariable("g:NERDTreeChDirMode", 1)
call s:InitVariable("g:NERDTreeChDirMode", 0)
if !exists("g:NERDTreeIgnore")
let g:NERDTreeIgnore = ['\~$']
endif
@@ -148,7 +148,7 @@ command! -n=1 -complete=customlist,s:CompleteBookmarks NERDTreeFromBookmark call
"Save the cursor position whenever we close the nerd tree
exec "autocmd BufWinLeave *". s:NERDTreeWinName ."* :call <SID>SaveScreenState()"
"cache bookmarks when vim loads
autocmd VimEnter * call s:oBookmark.CacheBookmarks()
autocmd VimEnter * call s:oBookmark.CacheBookmarks(0)
"SECTION: Classes {{{1
"============================================================
@@ -177,6 +177,17 @@ function! s:oBookmark.Bookmarks() dict
endif
return g:NERDTreeBookmarks
endfunction
" Function: oBookmark.BookmarkExistsFor(name) {{{3
" class method that returns 1 if a bookmark with the given name is found, 0
" otherwise
function! s:oBookmark.BookmarkExistsFor(name) dict
try
call s:oBookmark.BookmarkFor(a:name)
return 1
catch /NERDTree.BookmarkNotFound/
return 0
endtry
endfunction
" Function: oBookmark.BookmarkFor(name) {{{3
" Class method to get the bookmark that has the given name. {} is return if no
" bookmark is found
@@ -186,7 +197,7 @@ function! s:oBookmark.BookmarkFor(name) dict
return i
endif
endfor
return {}
throw "NERDTree.BookmarkNotFound exception: no bookmark found for name: \"". a:name .'"'
endfunction
" Function: oBookmark.BookmarkNames() {{{3
" Class method to return an array of all bookmark names
@@ -197,30 +208,42 @@ function! s:oBookmark.BookmarkNames() dict
endfor
return names
endfunction
" FUNCTION: oBookmark.CacheBookmarks() {{{3
" FUNCTION: oBookmark.CacheBookmarks(silent) {{{3
" Class method to read all bookmarks from the bookmarks file intialize
" bookmark objects for each one.
function! s:oBookmark.CacheBookmarks() dict
"
" Args:
" silent - dont echo an error msg if invalid bookmarks are found
function! s:oBookmark.CacheBookmarks(silent) dict
if filereadable(g:NERDTreeBookmarksFile)
let bookmarks = []
let g:NERDTreeBookmarks = []
let g:NERDTreeInvalidBookmarks = []
let bookmarkStrings = readfile(g:NERDTreeBookmarksFile)
let invalidBookmarksFound = 0
for i in bookmarkStrings
"ignore blank lines
if i != ''
let name = substitute(i, '^\(.\{-}\) .*$', '\1', '')
let path = substitute(i, '^.\{-} \(.*\)$', '\1', '')
try
let bookmark = s:oBookmark.New(name, s:oPath.New(path))
call add(bookmarks, bookmark)
call add(g:NERDTreeBookmarks, bookmark)
catch /NERDTree.Path.InvalidArguments/
call add(g:NERDTreeInvalidBookmarks, i)
let invalidBookmarksFound += 1
endtry
endfor
let g:NERDTreeBookmarks = bookmarks
if invalidBookmarksFound
call s:Echo(invalidBookmarksFound . " invalid bookmarks were read and discarded")
call s:oBookmark.Write()
endif
endfor
if invalidBookmarksFound
call s:oBookmark.Write()
if !a:silent
call s:Echo(invalidBookmarksFound . " invalid bookmarks were read. See :help NERDTreeInvalidBookmarks for info.")
endif
endif
call s:oBookmark.Sort()
endif
endfunction
" FUNCTION: oBookmark.CompareTo(otherbookmark) {{{3
@@ -249,6 +272,7 @@ function! s:oBookmark.Delete() dict
if !empty(node)
call node.path.CacheDisplayString()
endif
call s:oBookmark.Write()
endfunction
" FUNCTION: oBookmark.GetNode(searchFromAbsoluteRoot) {{{3
" Gets the treenode for this bookmark
@@ -260,7 +284,7 @@ function! s:oBookmark.GetNode(searchFromAbsoluteRoot) dict
let searchRoot = a:searchFromAbsoluteRoot ? s:AbsoluteTreeRoot() : t:NERDTreeRoot
let targetNode = searchRoot.FindNode(self.path)
if empty(targetNode)
throw "NERDTree.BookmarkNotFound no node was found for bookmark: " . self.name
throw "NERDTree.BookmarkedNodeNotFound no node was found for bookmark: " . self.name
endif
return targetNode
endfunction
@@ -269,11 +293,25 @@ endfunction
" treenode for it.
function! s:oBookmark.GetNodeForName(name, searchFromAbsoluteRoot) dict
let bookmark = s:oBookmark.BookmarkFor(a:name)
if bookmark == {}
throw "NERDTree.BookmarkNotFound no node was found for bookmark: " . a:name
endif
return bookmark.GetNode(a:searchFromAbsoluteRoot)
endfunction
" Function: oBookmark.InvalidBookmarks() {{{3
" Class method to get all invalid bookmark strings read from the bookmarks
" file
function! s:oBookmark.InvalidBookmarks() dict
if !exists("g:NERDTreeInvalidBookmarks")
let g:NERDTreeInvalidBookmarks = []
endif
return g:NERDTreeInvalidBookmarks
endfunction
" FUNCTION: oBookmark.MustExist() {{{3
function! s:oBookmark.MustExist() dict
if !self.path.Exists()
call s:oBookmark.CacheBookmarks(1)
throw "NERDTree.BookmarkPointsToInvalidLocation exception: the bookmark \"".
\ self.name ."\" points to a non existing location: \"". self.path.StrForOS(0)
endif
endfunction
" FUNCTION: oBookmark.New(name, path) {{{3
" Create a new bookmark object with the given name and path object
function! s:oBookmark.New(name, path) dict
@@ -286,6 +324,11 @@ function! s:oBookmark.New(name, path) dict
let newBookmark.path = a:path
return newBookmark
endfunction
" Function: oBookmark.SetPath(path) {{{3
" makes this bookmark point to the given path
function! s:oBookmark.SetPath(path) dict
let self.path = a:path
endfunction
" Function: oBookmark.Sort() {{{3
" Class method that sorts all bookmarks
function! s:oBookmark.Sort() dict
@@ -313,6 +356,13 @@ function! s:oBookmark.Write() dict
for i in s:oBookmark.Bookmarks()
call add(bookmarkStrings, i.name . ' ' . i.path.StrForOS(0))
endfor
"add a blank line before the invalid ones
call add(bookmarkStrings, "")
for j in s:oBookmark.InvalidBookmarks()
call add(bookmarkStrings, j)
endfor
call writefile(bookmarkStrings, g:NERDTreeBookmarksFile)
endfunction
"CLASS: oTreeFileNode {{{2
@@ -541,6 +591,7 @@ function! s:oTreeFileNode.Rename(newName) dict
if newParent != {}
call newParent.CreateChild(self.path, 1)
call newParent.Refresh()
endif
endfunction
"FUNCTION: oTreeFileNode.StrDisplay() {{{3
@@ -796,8 +847,8 @@ function! s:oTreeDirNode.InitChildren(silent) dict
try
let path = s:oPath.New(i)
call self.CreateChild(path, 0)
catch /^NERDTree.Path.InvalidArguments/
let invalidFilesFound = 1
catch /^NERDTree.Path.\(InvalidArguments\|InvalidFiletype\)/
let invalidFilesFound += 1
endtry
endif
endfor
@@ -809,7 +860,7 @@ function! s:oTreeDirNode.InitChildren(silent) dict
endif
if invalidFilesFound
call s:EchoWarning("some files could not be loaded into the NERD tree")
call s:EchoWarning(invalidFilesFound . " file(s) could not be loaded into the NERD tree")
endif
return self.GetChildCount()
endfunction
@@ -990,7 +1041,7 @@ endfunction
let s:oPath = {}
"FUNCTION: oPath.BookmarkNames() {{{3
function! s:oPath.BookmarkNames() dict
if !exists("self.bookmark")
if !exists("self.bookmarkNames")
call self.CacheDisplayString()
endif
return self.bookmarkNames
@@ -1003,14 +1054,14 @@ function! s:oPath.CacheDisplayString() dict
let self.cachedDisplayString = self.cachedDisplayString . '*'
endif
let bookmarkNames = []
let self.bookmarkNames = []
for i in s:oBookmark.Bookmarks()
if i.path.Equals(self)
call add(bookmarkNames, i.name)
call add(self.bookmarkNames, i.name)
endif
endfor
if !empty(bookmarkNames)
let self.cachedDisplayString .= ' {' . join(bookmarkNames) . '}'
if !empty(self.bookmarkNames)
let self.cachedDisplayString .= ' {' . join(self.bookmarkNames) . '}'
endif
if self.isSymLink
@@ -1196,6 +1247,12 @@ function! s:oPath.Delete() dict
throw "NERDTree.Path.Deletion Exception: Could not delete file: '" . self.Str(0) . "'"
endif
endif
"delete all bookmarks for this path
for i in self.BookmarkNames()
let bookmark = s:oBookmark.BookmarkFor(i)
call bookmark.Delete()
endfor
endfunction
"FUNCTION: oPath.ExtractDriveLetter(fullpath) {{{3
@@ -1209,6 +1266,11 @@ function! s:oPath.ExtractDriveLetter(fullpath) dict
endif
endfunction
"FUNCTION: oPath.Exists() {{{3
"return 1 if this path points to a location that is readable or is a directory
function! s:oPath.Exists() dict
return filereadable(self.StrForOS(0)) || isdirectory(self.StrForOS(0))
endfunction
"FUNCTION: oPath.GetDir() {{{3
"
"Returns this path if it is a directory, else this paths parent.
@@ -1340,8 +1402,13 @@ function! s:oPath.ReadInfoFromDisk(fullpath) dict
let fullpath = s:oPath.WinToUnixPath(a:fullpath)
if getftype(fullpath) == "fifo"
throw "NERDTree.Path.InvalidFiletype Exception: Cant handle FIFO files: " . a:fullpath
endif
let self.pathSegments = split(fullpath, '/')
let self.isReadOnly = 0
if isdirectory(a:fullpath)
let self.isDirectory = 1
@@ -1400,6 +1467,12 @@ function! s:oPath.Rename(newPath) dict
throw "NERDTree.Path.Rename Exception: Could not rename: '" . self.StrForOS(0) . "'" . 'to:' . a:newPath
endif
call self.ReadInfoFromDisk(a:newPath)
for i in self.BookmarkNames()
let b = s:oBookmark.BookmarkFor(i)
call b.SetPath(copy(self))
endfor
call s:oBookmark.Write()
endfunction
"FUNCTION: oPath.Str(esc) {{{3
@@ -1607,7 +1680,7 @@ endfunction
"name: the name of a bookmark or a directory
function! s:InitNerdTree(name)
let path = {}
if s:oBookmark.BookmarkFor(a:name) != {}
if s:oBookmark.BookmarkExistsFor(a:name)
let path = s:oBookmark.BookmarkFor(a:name).path
else
let dir = a:name == '' ? expand('%:p:h') : a:name
@@ -1697,6 +1770,21 @@ endfunction
" SECTION: View Functions {{{1
"============================================================
" FUNCTION: s:BookmarkToRoot(name) {{{2
" Make the node for the given bookmark the new tree root
function! s:BookmarkToRoot(name)
let bookmark = s:oBookmark.BookmarkFor(a:name)
if s:ValidateBookmark(bookmark)
try
let targetNode = s:oBookmark.GetNodeForName(a:name, 1)
catch /NERDTree.BookmarkedNodeNotFound/
let targetNode = s:oTreeFileNode.New(s:oBookmark.BookmarkFor(a:name).path)
endtry
call targetNode.MakeRoot()
call s:RenderView()
call s:PutCursorOnNode(targetNode, 0, 0)
endif
endfunction
"FUNCTION: s:CenterView() {{{2
"centers the nerd tree window around the cursor (provided the nerd tree
"options permit)
@@ -1710,13 +1798,6 @@ function! s:CenterView()
endif
endif
endfunction
"FUNCTION: s:CloseTreeIfOpen() {{{2
"Closes the NERD tree window if it is open
function! s:CloseTreeIfOpen()
if s:IsTreeOpen()
call s:CloseTree()
endif
endfunction
"FUNCTION: s:CloseTree() {{{2
"Closes the NERD tree window
function! s:CloseTree()
@@ -1733,6 +1814,20 @@ function! s:CloseTree()
endif
endfunction
"FUNCTION: s:CloseTreeIfOpen() {{{2
"Closes the NERD tree window if it is open
function! s:CloseTreeIfOpen()
if s:IsTreeOpen()
call s:CloseTree()
endif
endfunction
"FUNCTION: s:CloseTreeIfQuitOnOpen() {{{2
"Closes the NERD tree window if the close on open option is set
function! s:CloseTreeIfQuitOnOpen()
if g:NERDTreeQuitOnOpen
call s:CloseTree()
endif
endfunction
"FUNCTION: s:CreateTreeWin() {{{2
"Inits the NERD tree window. ie. opens it, sizes it, sets all the local
"options etc
@@ -2104,7 +2199,11 @@ function! s:GetSelectedBookmark()
let line = getline(".")
let name = substitute(line, '^>\(.\{-}\) \[.*\]$', '\1', '')
if name != line
try
return s:oBookmark.BookmarkFor(name)
catch /NERDTree.BookmarkNotFound/
return {}
endtry
endif
endfunction
@@ -2222,7 +2321,7 @@ function! s:OpenFileNode(treenode)
call s:PutCursorInTreeWin()
"if the file is already open in this tab then just stick the cursor in it
let winnr = bufwinnr(a:treenode.path.StrForOS(0))
let winnr = bufwinnr('^' . a:treenode.path.StrForOS(0) . '$')
if winnr != -1
exec winnr . "wincmd w"
@@ -2356,6 +2455,25 @@ function! s:PromptToDelBuffer(bufnum, msg)
endif
endfunction
"FUNCTION: s:PutCursorOnBookmarkTable(){{{2
"Places the cursor at the top of the bookmarks table
function! s:PutCursorOnBookmarkTable()
if !t:NERDTreeShowBookmarks
throw "NERDTree.IllegalOperation exception: cant find bookmark table, bookmarks arent active"
endif
let rootNodeLine = s:FindRootNodeLineNumber()
let line = 1
while getline(line) !~ '^>-\+Bookmarks-\+$'
let line = line + 1
if line >= rootNodeLine
throw "NERDTree.BookmarkTableNotFound exception: didnt find the bookmarks table"
endif
endwhile
call cursor(line, 0)
endfunction
"FUNCTION: s:PutCursorOnNode(treenode, isJump, recurseUpward){{{2
"Places the cursor on the line number representing the given node
"
@@ -2696,12 +2814,27 @@ function! s:Toggle(dir)
call s:InitNerdTree(a:dir)
endif
endfunction
"FUNCTION: s:ValidateBookmark(bookmark) {{{2
function! s:ValidateBookmark(bookmark)
try
call a:bookmark.MustExist()
return 1
catch /NERDTree.BookmarkPointsToInvalidLocation/
call s:RenderView()
call s:Echo(a:bookmark.name . "now points to an invalid location. See :help NERDTreeInvalidBookmarks for info.")
endtry
endfunction
"SECTION: Interface bindings {{{1
"============================================================
"FUNCTION: s:ActivateNode() {{{2
"FUNCTION: s:ActivateNode(forceKeepWindowOpen) {{{2
"If the current node is a file, open it in the previous window (or a new one
"if the previous is modified). If it is a directory then it is opened.
function! s:ActivateNode()
"
"args:
"forceKeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set
function! s:ActivateNode(forceKeepWindowOpen)
if getline(".") == s:tree_up_dir_line
return s:UpDir(0)
endif
@@ -2714,9 +2847,9 @@ function! s:ActivateNode()
call s:PutCursorOnNode(treenode, 0, 0)
else
call s:OpenFileNode(treenode)
if g:NERDTreeQuitOnOpen
call s:CloseTree()
endif
if !a:forceKeepWindowOpen
call s:CloseTreeIfQuitOnOpen()
end
endif
else
let bookmark = s:GetSelectedBookmark()
@@ -2724,10 +2857,12 @@ function! s:ActivateNode()
if bookmark.path.isDirectory
call s:BookmarkToRoot(bookmark.name)
else
if s:ValidateBookmark(bookmark)
call s:OpenFileNode(s:oTreeFileNode.New(bookmark.path))
endif
endif
endif
endif
endfunction
"FUNCTION: s:BindMappings() {{{2
@@ -2735,10 +2870,10 @@ function! s:BindMappings()
" set up mappings and commands for this buffer
nnoremap <silent> <buffer> <middlerelease> :call <SID>HandleMiddleMouse()<cr>
nnoremap <silent> <buffer> <leftrelease> <leftrelease>:call <SID>CheckForActivate()<cr>
nnoremap <silent> <buffer> <2-leftmouse> :call <SID>ActivateNode()<cr>
nnoremap <silent> <buffer> <2-leftmouse> :call <SID>ActivateNode(0)<cr>
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapActivateNode . " :call <SID>ActivateNode()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenSplit ." :call <SID>OpenEntrySplit()<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapActivateNode . " :call <SID>ActivateNode(0)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenSplit ." :call <SID>OpenEntrySplit(0)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapPreview ." :call <SID>PreviewNode(0)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapPreviewSplit ." :call <SID>PreviewNode(1)<cr>"
@@ -2788,7 +2923,7 @@ function! s:BindMappings()
command! -buffer -complete=customlist,s:CompleteBookmarks -nargs=* ClearBookmarks call <SID>ClearBookmarks('<args>')
command! -buffer -complete=customlist,s:CompleteBookmarks -nargs=+ BookmarkToRoot call <SID>BookmarkToRoot('<args>')
command! -buffer -nargs=0 ClearAllBookmarks call s:oBookmark.ClearAll() <bar> call <SID>RenderView()
command! -buffer -nargs=0 ReadBookmarks call s:oBookmark.CacheBookmarks() <bar> call <SID>RenderView()
command! -buffer -nargs=0 ReadBookmarks call s:oBookmark.CacheBookmarks(0) <bar> call <SID>RenderView()
command! -buffer -nargs=0 WriteBookmarks call s:oBookmark.Write()
endfunction
@@ -2807,18 +2942,6 @@ function! s:BookmarkNode(name)
call s:Echo("select a node first")
endif
endfunction
" FUNCTION: s:BookmarkToRoot(name) {{{2
" Make the node for the given bookmark the new tree root
function! s:BookmarkToRoot(name)
try
let targetNode = s:oBookmark.GetNodeForName(a:name, 1)
catch /NERDTree.BookmarkNotFound/
let targetNode = s:oTreeFileNode.New(s:oBookmark.BookmarkFor(a:name).path)
endtry
call targetNode.MakeRoot()
call s:RenderView()
call s:PutCursorOnNode(targetNode, 0, 0)
endfunction
"FUNCTION: s:CheckForActivate() {{{2
"Checks if the click should open the current node, if so then activate() is
"called (directories are automatically opened if the symbol beside them is
@@ -2834,14 +2957,14 @@ function! s:CheckForActivate()
if currentNode.path.isDirectory
let reg = '^' . s:tree_markup_reg .'*[~+]$'
if startToCur =~ reg
call s:ActivateNode()
call s:ActivateNode(0)
return
endif
endif
if (g:NERDTreeMouseMode == 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode == 3
if char !~ s:tree_markup_reg && startToCur !~ '\/$'
call s:ActivateNode()
call s:ActivateNode(0)
return
endif
endif
@@ -2890,7 +3013,6 @@ function! s:ClearBookmarks(bookmarks)
call bookmark.Delete()
endfor
endif
call s:oBookmark.Write()
call s:RenderView()
endfunction
" FUNCTION: s:CloseChildren() {{{2
@@ -3054,7 +3176,7 @@ function! s:HandleMiddleMouse()
if curNode.path.isDirectory
call s:OpenExplorer()
else
call s:OpenEntrySplit()
call s:OpenEntrySplit(0)
endif
endfunction
@@ -3155,7 +3277,7 @@ function! s:OpenBookmark(name)
let targetNode = s:oBookmark.GetNodeForName(a:name, 0)
call s:PutCursorOnNode(targetNode, 0, 1)
redraw!
catch /NERDTree.BookmarkNotFound/
catch /NERDTree.BookmarkedNodeNotFound/
call s:Echo("note - target node is not cached")
let bookmark = s:oBookmark.BookmarkFor(a:name)
let targetNode = s:oTreeFileNode.New(bookmark.path)
@@ -3166,15 +3288,18 @@ function! s:OpenBookmark(name)
call s:OpenFileNode(targetNode)
endif
endfunction
" FUNCTION: s:OpenEntrySplit() {{{2
" FUNCTION: s:OpenEntrySplit(forceKeepWindowOpen) {{{2
"Opens the currently selected file from the explorer in a
"new window
function! s:OpenEntrySplit()
"
"args:
"forceKeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set
function! s:OpenEntrySplit(forceKeepWindowOpen)
let treenode = s:GetSelectedNode()
if treenode != {}
call s:OpenFileNodeSplit(treenode)
if g:NERDTreeQuitOnOpen
call s:CloseTree()
if !a:forceKeepWindowOpen
call s:CloseTreeIfQuitOnOpen()
endif
else
call s:Echo("select a node first")
@@ -3201,23 +3326,26 @@ function! s:OpenInNewTab(stayCurrentTab)
let treenode = s:GetSelectedNode()
if treenode != {}
if treenode.path.isDirectory
tabnew
call s:InitNerdTree(treenode.path.StrForOS(0))
else
exec "tabedit " . treenode.path.StrForEditCmd()
if a:stayCurrentTab
exec "tabnext " . currentTab
endif
else
let bookmark = s:GetSelectedBookmark()
if bookmark != {}
if bookmark.path.isDirectory
exec "tabnew +NERDTreeFromBookmark\\ " . bookmark.name
tabnew
call s:InitNerdTree(bookmark.name)
else
exec "tabedit " . bookmark.path.StrForEditCmd()
endif
endif
endif
if a:stayCurrentTab
exec "tabnext " . currentTab
endif
endif
endif
endfunction
" FUNCTION: s:OpenNodeRecursively() {{{2
@@ -3237,16 +3365,10 @@ endfunction
"FUNCTION: s:PreviewNode() {{{2
function! s:PreviewNode(openNewWin)
let treenode = s:GetSelectedNode()
if treenode == {} || treenode.path.isDirectory
call s:Echo("Select a file node first" )
return
endif
if a:openNewWin
call s:OpenEntrySplit()
call s:OpenEntrySplit(1)
else
call s:ActivateNode()
call s:ActivateNode(1)
end
call s:PutCursorInTreeWin()
endfunction
@@ -3375,7 +3497,12 @@ endfunction
" toggles the display of bookmarks
function! s:ToggleShowBookmarks()
let t:NERDTreeShowBookmarks = !t:NERDTreeShowBookmarks
if t:NERDTreeShowBookmarks
call s:RenderView()
call s:PutCursorOnBookmarkTable()
else
call s:RenderViewSavingPosition()
endif
call s:CenterView()
endfunction
" FUNCTION: s:ToggleShowFiles() {{{2