From 0ad0d195e5285263129f5be268dceebff3ae53ed Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Fri, 11 Jul 2008 21:17:29 +1200 Subject: [PATCH] make NERDTreeQuitOnOpen option work with g/go --- doc/NERD_tree.txt | 2 ++ plugin/NERD_tree.vim | 67 ++++++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt index 2ff1cdd..2173b56 100644 --- a/doc/NERD_tree.txt +++ b/doc/NERD_tree.txt @@ -878,6 +878,8 @@ fridge for later ;) - 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 and go mappings, + thanks to Maxim Kim for the bug report 2.12.0 - added a UI for bookmarks. See :help NERDTreeBookmarkTable for details. diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 5012e3c..9a339cb 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -1722,13 +1722,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() @@ -1745,6 +1738,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 @@ -2729,10 +2736,13 @@ function! s:Toggle(dir) 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 @@ -2745,9 +2755,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() @@ -2766,10 +2776,10 @@ function! s:BindMappings() " set up mappings and commands for this buffer nnoremap :call HandleMiddleMouse() nnoremap :call CheckForActivate() - nnoremap <2-leftmouse> :call ActivateNode() + nnoremap <2-leftmouse> :call ActivateNode(0) - exec "nnoremap ". g:NERDTreeMapActivateNode . " :call ActivateNode()" - exec "nnoremap ". g:NERDTreeMapOpenSplit ." :call OpenEntrySplit()" + exec "nnoremap ". g:NERDTreeMapActivateNode . " :call ActivateNode(0)" + exec "nnoremap ". g:NERDTreeMapOpenSplit ." :call OpenEntrySplit(0)" exec "nnoremap ". g:NERDTreeMapPreview ." :call PreviewNode(0)" exec "nnoremap ". g:NERDTreeMapPreviewSplit ." :call PreviewNode(1)" @@ -3085,7 +3095,7 @@ function! s:HandleMiddleMouse() if curNode.path.isDirectory call s:OpenExplorer() else - call s:OpenEntrySplit() + call s:OpenEntrySplit(0) endif endfunction @@ -3197,15 +3207,18 @@ function! s:OpenBookmark(name) call s:OpenFileNode(targetNode) endif endfunction -" FUNCTION: s:OpenEntrySplit() {{{2 -" Opens the currently selected file from the explorer in a -" new window -function! s:OpenEntrySplit() +" FUNCTION: s:OpenEntrySplit(forceKeepWindowOpen) {{{2 +"Opens the currently selected file from the explorer in a +"new window +" +"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") @@ -3271,16 +3284,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