From 3e946b1b4fd831f992ed06fec418a1b3f1eada65 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 28 Jun 2008 20:43:33 +1200 Subject: [PATCH] make 'o' active bookmarks as well hitting 'o' or clicking a bookmark will now make that bookmark to the new tree root, in the same way that :BookmarkToRoot does --- plugin/NERD_tree.vim | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 366cce8..f4f241c 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -1990,6 +1990,17 @@ function! s:GetPath(ln) return toReturn endfunction +"FUNCTION: s:GetSelectedBookmark() {{{2 +"Returns the current node if it is a dir node, or else returns the current +"nodes parent +function! s:GetSelectedBookmark() + let line = getline(".") + let name = substitute(line, '^>\(.\{-}\) \[.*\]$', '\1', '') + if name != line + return name + endif +endfunction + "FUNCTION: s:GetSelectedDir() {{{2 "Returns the current node if it is a dir node, or else returns the current "nodes parent @@ -2572,20 +2583,23 @@ function! s:ActivateNode() if getline(".") == s:tree_up_dir_line return s:UpDir(0) endif - let treenode = s:GetSelectedNode() - if treenode == {} - call s:EchoWarning("cannot open selected entry") - return - endif - if treenode.path.isDirectory - call treenode.ToggleOpen() - call s:RenderView() - call s:PutCursorOnNode(treenode, 0, 0) + let treenode = s:GetSelectedNode() + if treenode != {} + if treenode.path.isDirectory + call treenode.ToggleOpen() + call s:RenderView() + call s:PutCursorOnNode(treenode, 0, 0) + else + call s:OpenFileNode(treenode) + if g:NERDTreeQuitOnOpen + call s:CloseTree() + endif + endif else - call s:OpenFileNode(treenode) - if g:NERDTreeQuitOnOpen - call s:CloseTree() + let bookmark = s:GetSelectedBookmark() + if bookmark != "" + call s:BookmarkToRoot(bookmark) endif endif endfunction