commit 87b27802b57bbf383a812b57338fbab28499b7e8
parent 1cbd52aa77541682658f4c8a6d217c77a78c3879
Author: Martin Grenfell <martin.grenfell@gmail.com>
Date: Fri, 1 May 2015 15:33:06 +0100
allow control over whether to reuse windows in different tabs
When opening a file we will "reuse" a window if the buffer is already
open somewhere.
Add an option to NERDTreeOpener to configure it to not reuse windows
across tabs.
Diffstat:
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/autoload/nerdtree/ui_glue.vim b/autoload/nerdtree/ui_glue.vim
@@ -93,13 +93,13 @@ endfunction
"FUNCTION: s:activateDirNode() {{{1
"handle the user activating a tree node
function! s:activateDirNode(node)
- call a:node.activate({'reuse': 1})
+ call a:node.activate()
endfunction
"FUNCTION: s:activateFileNode() {{{1
"handle the user activating a tree node
function! s:activateFileNode(node)
- call a:node.activate({'reuse': 1, 'where': 'p'})
+ call a:node.activate({'reuse': 'all', 'where': 'p'})
endfunction
"FUNCTION: s:activateBookmark() {{{1
@@ -324,7 +324,7 @@ function! s:handleLeftClick()
if currentNode.path.isDirectory
call currentNode.activate()
else
- call currentNode.activate({'reuse': 1, 'where': 'p'})
+ call currentNode.activate({'reuse': 'all', 'where': 'p'})
endif
return
endif
diff --git a/lib/nerdtree/opener.vim b/lib/nerdtree/opener.vim
@@ -131,7 +131,8 @@ endfunction
" 'where': Specifies whether the node should be opened in new split/tab or in
" the previous window. Can be either 'v' or 'h' or 't' (for open in
" new tab)
-" 'reuse': if a window is displaying the file then jump the cursor there
+" 'reuse': if a window is displaying the file then jump the cursor there. Can
+" 'all', 'currenttab' or empty to not reuse.
" 'keepopen': dont close the tree window
" 'stay': open the file, but keep the cursor in the tree win
function! s:Opener.New(path, opts)
@@ -139,7 +140,13 @@ function! s:Opener.New(path, opts)
let newObj._path = a:path
let newObj._stay = nerdtree#has_opt(a:opts, 'stay')
- let newObj._reuse = nerdtree#has_opt(a:opts, 'reuse')
+
+ if has_key(a:opts, 'reuse')
+ let newObj._reuse = a:opts['reuse']
+ else
+ let newObj._reuse = ''
+ endif
+
let newObj._keepopen = nerdtree#has_opt(a:opts, 'keepopen')
let newObj._where = has_key(a:opts, 'where') ? a:opts['where'] : ''
let newObj._treetype = b:NERDTreeType
@@ -235,7 +242,7 @@ endfunction
"FUNCTION: Opener._openFile() {{{1
function! s:Opener._openFile()
- if self._reuse && self._reuseWindow()
+ if self._reuseWindow()
return
endif
@@ -307,23 +314,32 @@ endfunction
"
"return 1 if we were successful
function! s:Opener._reuseWindow()
+ if empty(self._reuse)
+ return 0
+ endif
+
"check the current tab for the window
let winnr = bufwinnr('^' . self._path.str() . '$')
if winnr != -1
call nerdtree#exec(winnr . "wincmd w")
call self._checkToCloseTree(0)
return 1
- else
- "check other tabs
- let tabnr = self._path.tabnr()
- if tabnr
- call self._checkToCloseTree(1)
- call nerdtree#exec('normal! ' . tabnr . 'gt')
- let winnr = bufwinnr('^' . self._path.str() . '$')
- call nerdtree#exec(winnr . "wincmd w")
- return 1
- endif
endif
+
+ if self._reuse == 'currenttab'
+ return 0
+ endif
+
+ "check other tabs
+ let tabnr = self._path.tabnr()
+ if tabnr
+ call self._checkToCloseTree(1)
+ call nerdtree#exec('normal! ' . tabnr . 'gt')
+ let winnr = bufwinnr('^' . self._path.str() . '$')
+ call nerdtree#exec(winnr . "wincmd w")
+ return 1
+ endif
+
return 0
endfunction