make NERDTreeQuitOnOpen option work with g<tab>/go

This commit is contained in:
Martin Grenfell 2008-07-11 21:17:29 +12:00
parent 43bf05c42e
commit 0ad0d195e5
2 changed files with 39 additions and 30 deletions

View File

@ -878,6 +878,8 @@ fridge for later ;)
- make the t/T on directory nodes open a fresh NERD tree for the selected - make the t/T on directory nodes open a fresh NERD tree for the selected
dir in a new tab, rather than a netrw. dir in a new tab, rather than a netrw.
- place the cursor at the top of the bookmarks table when opening it with B - 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
2.12.0 2.12.0
- added a UI for bookmarks. See :help NERDTreeBookmarkTable for details. - added a UI for bookmarks. See :help NERDTreeBookmarkTable for details.

View File

@ -1722,13 +1722,6 @@ function! s:CenterView()
endif endif
endif endif
endfunction 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 "FUNCTION: s:CloseTree() {{{2
"Closes the NERD tree window "Closes the NERD tree window
function! s:CloseTree() function! s:CloseTree()
@ -1745,6 +1738,20 @@ function! s:CloseTree()
endif endif
endfunction 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 "FUNCTION: s:CreateTreeWin() {{{2
"Inits the NERD tree window. ie. opens it, sizes it, sets all the local "Inits the NERD tree window. ie. opens it, sizes it, sets all the local
"options etc "options etc
@ -2729,10 +2736,13 @@ function! s:Toggle(dir)
endfunction endfunction
"SECTION: Interface bindings {{{1 "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 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. "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 if getline(".") == s:tree_up_dir_line
return s:UpDir(0) return s:UpDir(0)
endif endif
@ -2745,9 +2755,9 @@ function! s:ActivateNode()
call s:PutCursorOnNode(treenode, 0, 0) call s:PutCursorOnNode(treenode, 0, 0)
else else
call s:OpenFileNode(treenode) call s:OpenFileNode(treenode)
if g:NERDTreeQuitOnOpen if !a:forceKeepWindowOpen
call s:CloseTree() call s:CloseTreeIfQuitOnOpen()
endif end
endif endif
else else
let bookmark = s:GetSelectedBookmark() let bookmark = s:GetSelectedBookmark()
@ -2766,10 +2776,10 @@ function! s:BindMappings()
" set up mappings and commands for this buffer " set up mappings and commands for this buffer
nnoremap <silent> <buffer> <middlerelease> :call <SID>HandleMiddleMouse()<cr> nnoremap <silent> <buffer> <middlerelease> :call <SID>HandleMiddleMouse()<cr>
nnoremap <silent> <buffer> <leftrelease> <leftrelease>:call <SID>CheckForActivate()<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:NERDTreeMapActivateNode . " :call <SID>ActivateNode(0)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapOpenSplit ." :call <SID>OpenEntrySplit()<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:NERDTreeMapPreview ." :call <SID>PreviewNode(0)<cr>"
exec "nnoremap <silent> <buffer> ". g:NERDTreeMapPreviewSplit ." :call <SID>PreviewNode(1)<cr>" exec "nnoremap <silent> <buffer> ". g:NERDTreeMapPreviewSplit ." :call <SID>PreviewNode(1)<cr>"
@ -3085,7 +3095,7 @@ function! s:HandleMiddleMouse()
if curNode.path.isDirectory if curNode.path.isDirectory
call s:OpenExplorer() call s:OpenExplorer()
else else
call s:OpenEntrySplit() call s:OpenEntrySplit(0)
endif endif
endfunction endfunction
@ -3197,15 +3207,18 @@ function! s:OpenBookmark(name)
call s:OpenFileNode(targetNode) call s:OpenFileNode(targetNode)
endif endif
endfunction endfunction
" FUNCTION: s:OpenEntrySplit() {{{2 " FUNCTION: s:OpenEntrySplit(forceKeepWindowOpen) {{{2
" Opens the currently selected file from the explorer in a "Opens the currently selected file from the explorer in a
" new window "new window
function! s:OpenEntrySplit() "
"args:
"forceKeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set
function! s:OpenEntrySplit(forceKeepWindowOpen)
let treenode = s:GetSelectedNode() let treenode = s:GetSelectedNode()
if treenode != {} if treenode != {}
call s:OpenFileNodeSplit(treenode) call s:OpenFileNodeSplit(treenode)
if g:NERDTreeQuitOnOpen if !a:forceKeepWindowOpen
call s:CloseTree() call s:CloseTreeIfQuitOnOpen()
endif endif
else else
call s:Echo("select a node first") call s:Echo("select a node first")
@ -3271,16 +3284,10 @@ endfunction
"FUNCTION: s:PreviewNode() {{{2 "FUNCTION: s:PreviewNode() {{{2
function! s:PreviewNode(openNewWin) 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 if a:openNewWin
call s:OpenEntrySplit() call s:OpenEntrySplit(1)
else else
call s:ActivateNode() call s:ActivateNode(1)
end end
call s:PutCursorInTreeWin() call s:PutCursorInTreeWin()
endfunction endfunction