combine NERDTreeSplitVertical and NERDTreeWinPos

instead of using 2 options to specify the position of the tree, just use
NERDTreeWinPos and set it to "left", "right", "top", "bottom"
This commit is contained in:
Martin Grenfell
2008-06-29 19:43:50 +12:00
parent c34968d282
commit 5f4a002787

View File

@@ -73,8 +73,7 @@ endif
"once here "once here
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*') let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
call s:InitVariable("g:NERDTreeSplitVertical", 1) call s:InitVariable("g:NERDTreeWinPos", "left")
call s:InitVariable("g:NERDTreeWinPos", 1)
call s:InitVariable("g:NERDTreeWinSize", 31) call s:InitVariable("g:NERDTreeWinSize", 31)
let s:running_windows = has("win16") || has("win32") || has("win64") let s:running_windows = has("win16") || has("win32") || has("win64")
@@ -1719,8 +1718,8 @@ endfunction
"options etc "options etc
function! s:CreateTreeWin() function! s:CreateTreeWin()
"create the nerd tree window "create the nerd tree window
let splitLocation = g:NERDTreeWinPos ? "topleft " : "botright " let splitLocation = (g:NERDTreeWinPos == "top" || g:NERDTreeWinPos == "left") ? "topleft " : "botright "
let splitMode = g:NERDTreeSplitVertical ? "vertical " : "" let splitMode = s:ShouldSplitVertically() ? "vertical " : ""
let splitSize = g:NERDTreeWinSize let splitSize = g:NERDTreeWinSize
let t:NERDTreeWinName = localtime() . s:NERDTreeWinName let t:NERDTreeWinName = localtime() . s:NERDTreeWinName
let cmd = splitLocation . splitMode . splitSize . ' new ' . t:NERDTreeWinName let cmd = splitLocation . splitMode . splitSize . ' new ' . t:NERDTreeWinName
@@ -2264,16 +2263,16 @@ function! s:OpenNodeSplit(treenode)
" 'right' and 'below' will be set to the settings needed for " 'right' and 'below' will be set to the settings needed for
" splitbelow and splitright IF the explorer is the only window. " splitbelow and splitright IF the explorer is the only window.
" "
if g:NERDTreeSplitVertical == 1 if s:ShouldSplitVertically()
let there= g:NERDTreeWinPos ? "wincmd h" : "wincmd l" let there= g:NERDTreeWinPos == "left" ? "wincmd h" : "wincmd l"
let back= g:NERDTreeWinPos ? "wincmd l" : "wincmd h" let back = g:NERDTreeWinPos == "left" ? "wincmd l" : "wincmd h"
let right=g:NERDTreeWinPos ? 1 : 0 let right= g:NERDTreeWinPos == "left"
let below=0 let below=0
else else
let there= g:NERDTreeWinPos ? "wincmd k" : "wincmd j" let there= g:NERDTreeWinPos == "top" ? "wincmd k" : "wincmd j"
let back= g:NERDTreeWinPos ? "wincmd j" : "wincmd k" let back = g:NERDTreeWinPos == "top" ? "wincmd j" : "wincmd k"
let below= g:NERDTreeWinPos == "top"
let right=0 let right=0
let below=g:NERDTreeWinPos ? 1 : 0
endif endif
" Attempt to go to adjacent window " Attempt to go to adjacent window
@@ -2293,10 +2292,12 @@ function! s:OpenNodeSplit(treenode)
" Create a variable to use if splitting vertically " Create a variable to use if splitting vertically
let splitMode = "" let splitMode = ""
if (onlyOneWin && g:NERDTreeSplitVertical) || (!onlyOneWin && !g:NERDTreeSplitVertical) if (onlyOneWin && s:ShouldSplitVertically()) || (!onlyOneWin && !s:ShouldSplitVertically())
let splitMode = "vertical" let splitMode = "vertical"
endif endif
echomsg splitMode
" Open the new window " Open the new window
try try
exec("silent " . splitMode." sp " . a:treenode.path.StrForEditCmd()) exec("silent " . splitMode." sp " . a:treenode.path.StrForEditCmd())
@@ -2469,7 +2470,7 @@ function! s:RestoreScreenState()
if !exists("t:NERDTreeOldTopLine") || !exists("t:NERDTreeOldPos") || !exists("t:NERDTreeOldWindowSize") if !exists("t:NERDTreeOldTopLine") || !exists("t:NERDTreeOldPos") || !exists("t:NERDTreeOldWindowSize")
return return
endif endif
exec("silent ". (g:NERDTreeSplitVertical ? "vertical" : "") ." resize ".t:NERDTreeOldWindowSize) exec("silent ". (s:ShouldSplitVertically() ? "vertical" : "") ." resize ".t:NERDTreeOldWindowSize)
let old_scrolloff=&scrolloff let old_scrolloff=&scrolloff
let &scrolloff=0 let &scrolloff=0
@@ -2487,7 +2488,7 @@ endfunction
function! s:SaveScreenState() function! s:SaveScreenState()
let t:NERDTreeOldPos = getpos(".") let t:NERDTreeOldPos = getpos(".")
let t:NERDTreeOldTopLine = line("w0") let t:NERDTreeOldTopLine = line("w0")
let t:NERDTreeOldWindowSize = g:NERDTreeSplitVertical ? winwidth("") : winheight("") let t:NERDTreeOldWindowSize = s:ShouldSplitVertically() ? winwidth("") : winheight("")
endfunction endfunction
"FUNCTION: s:SetupSyntaxHighlighting() {{{2 "FUNCTION: s:SetupSyntaxHighlighting() {{{2
@@ -2612,6 +2613,11 @@ function! s:ShouldSplitToOpen(winnumber)
return modified && s:BufInWindows(winbufnr(a:winnumber)) < 2 return modified && s:BufInWindows(winbufnr(a:winnumber)) < 2
endfunction endfunction
" Function: s:ShouldSplitVertically() {{{2
" Returns 1 if g:NERDTreeWinPos is 'left' or 'right'
function! s:ShouldSplitVertically()
return g:NERDTreeWinPos == 'left' || g:NERDTreeWinPos == 'right'
endfunction
"FUNCTION: s:StripMarkupFromLine(line, removeLeadingSpaces){{{2 "FUNCTION: s:StripMarkupFromLine(line, removeLeadingSpaces){{{2
"returns the given line with all the tree parts stripped off "returns the given line with all the tree parts stripped off
" "