From 2ecd6ebd637872dc455bbf52660da9965af1bf22 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Sat, 7 Jun 2008 12:45:21 +1200 Subject: [PATCH] add s:MarkForNode() and refactor to use it --- plugin/NERD_tree.vim | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 50c9937..9bee92d 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -1345,6 +1345,21 @@ function! s:BufInWindows(bnum) return cnt endfunction " >>> +"FUNCTION: s:GetNodeForMark(name) {{{2 +"get the treenode for the mark with the given name +function! s:GetNodeForMark(name) + try + let mark = s:GetMarks()[a:name] + catch /E716/ "key not in dictionary error + throw "NERDTree.MarkDoesntExist no mark found with name: " . a:name + endtry + + let targetNode = t:NERDTreeRoot.FindNode(mark) + if empty(targetNode) + throw "NERDTree.MarkNotFound no node was found for mark: " . a:name + endif + call s:PutCursorOnNode(targetNode, 0, 1) +endfunction "FUNCTION: s:InitNerdTree(dir) {{{2 "Initialized the NERD tree, where the root will be initialized with the given "directory @@ -2818,14 +2833,7 @@ endfunction " FUNCTION: s:OpenMark(name) {{{2 " put the cursor on the given mark and, if its a file, open it function! s:OpenMark(name) - try - let mark = s:GetMarks()[a:name] - catch /E716/ "key not in dictionary error - call s:Echo("Mark doesnt exist") - return - endtry - - let targetNode = t:NERDTreeRoot.FindNode(mark) + let targetNode = s:GetNodeForMark(a:name) call s:PutCursorOnNode(targetNode, 0, 1) redraw! if !targetNode.path.isDirectory @@ -2887,14 +2895,7 @@ endfunction " FUNCTION: s:RecallMark(name) {{{2 " put the cursor on the node associate with the given name function! s:RecallMark(name) - try - let mark = s:GetMarks()[a:name] - catch /E716/ "key not in dictionary error - call s:Echo("Mark doesnt exist") - return - endtry - - let targetNode = t:NERDTreeRoot.FindNode(mark) + let targetNode = s:GetNodeForMark(a:name) call s:PutCursorOnNode(targetNode, 0, 1) endfunction " FUNCTION: s:RefreshRoot() {{{2