From fb3c4f9212d356c7a0e3b96e5dabcfa1152d4a99 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Thu, 5 Jun 2008 22:41:05 +1200 Subject: [PATCH] add marking functionality add ability to give a node a name and the abiliy to jump back to the node for a given name --- plugin/NERD_tree.vim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 8ac50cc..8cbd9a8 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -1673,6 +1673,12 @@ function! s:EchoError(msg) call s:Echo(a:msg) echohl normal endfunction +" FUNCTION: s:FindMarks(A,L,P) {{{2 +" completion function for the RecallMark command +function! s:FindMarks(A,L,P) + let keys = keys(s:GetMarks()) + return filter(keys, 'v:val =~ "^' . a:A . '"') +endfunction "FUNCTION: s:FindNodeLineNumber(treenode){{{2 "Finds the line number for the given tree node " @@ -1735,6 +1741,14 @@ function! s:FindRootNodeLineNumber() return rootLine endfunction +" FUNCTION: s:GetMarks(name) {{{2 +" getter/lazy initializer for the t:NERDTreeMarks hash +function! s:GetMarks() + if !exists("t:NERDTreeMarks") + let t:NERDTreeMarks = {} + endif + return t:NERDTreeMarks +endfunction "FUNCTION: s:GetPath(ln) {{{2 "Gets the full path to the node that is rendered on the given line number " @@ -2385,6 +2399,9 @@ function! s:BindMappings() exec "nnoremap ". g:NERDTreeMapOpenInTabSilent ." :call OpenNodeNewTab(1)" exec "nnoremap ". g:NERDTreeMapOpenExpl ." :call OpenExplorer()" + + command! -buffer -nargs=1 Mark :call MarkNode('') + command! -buffer -complete=customlist,s:FindMarks -nargs=1 RecallMark :call RecallMark('') endfunction "FUNCTION: s:CheckForActivate() {{{2 @@ -2722,6 +2739,17 @@ function! s:JumpToSibling(forward) endif endfunction +" FUNCTION: s:MarkNode(name) {{{2 +" Associate the current node with the given name +function! s:MarkNode(name) + let currentNode = s:GetSelectedNode() + if currentNode != {} + let marks = s:GetMarks() + let marks[a:name] = currentNode.path + else + call s:Echo("select a node first") + endif +endfunction " FUNCTION: s:OpenEntrySplit() {{{2 " Opens the currently selected file from the explorer in a " new window @@ -2803,6 +2831,13 @@ function! s:PreviewNode(openNewWin) call s:PutCursorInTreeWin() endfunction +" FUNCTION: s:RecallMark(name) {{{2 +" put the cursor on the node associate with the given name +function! s:RecallMark(name) + let mark = s:GetMarks()[a:name] + let targetNode = t:NERDTreeRoot.FindNode(mark) + call s:PutCursorOnNode(targetNode, 0, 1) +endfunction " FUNCTION: s:RefreshRoot() {{{2 " Reloads the current root. All nodes below this will be lost and the root dir " will be reloaded.