refactor 3 more functions out of the monolithic autoload file

This commit is contained in:
Martin Grenfell 2015-05-02 12:42:59 +01:00
parent f8499462c5
commit 973c9906f8
3 changed files with 29 additions and 31 deletions

View File

@ -95,25 +95,6 @@ function! nerdtree#runningWindows()
return has("win16") || has("win32") || has("win64") return has("win16") || has("win32") || has("win64")
endfunction endfunction
"FUNCTION: nerdtree#treeMarkupReg(dir) {{{2
function! nerdtree#treeMarkupReg()
if g:NERDTreeDirArrows
return '^\([▾▸] \| \+[▾▸] \| \+\)'
endif
return '^[ `|]*[\-+~]'
endfunction
"FUNCTION: nerdtree#treeUpDirLine(dir) {{{2
function! nerdtree#treeUpDirLine()
return '.. (up a dir)'
endfunction
"FUNCTION: nerdtree#treeWid(dir) {{{2
function! nerdtree#treeWid()
return 2
endfunction
" SECTION: View Functions {{{1 " SECTION: View Functions {{{1
"============================================================ "============================================================
@ -374,7 +355,7 @@ endfunction
function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces) function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces)
let line = a:line let line = a:line
"remove the tree parts and the leading space "remove the tree parts and the leading space
let line = substitute (line, nerdtree#treeMarkupReg(),"","") let line = substitute (line, g:NERDTreeUI.MarkupReg(),"","")
"strip off any read only flag "strip off any read only flag
let line = substitute (line, ' \[RO\]', "","") let line = substitute (line, ' \[RO\]', "","")

View File

@ -85,7 +85,7 @@ endfunction
"FUNCTION: s:activateAll() {{{1 "FUNCTION: s:activateAll() {{{1
"handle the user activating the updir line "handle the user activating the updir line
function! s:activateAll() function! s:activateAll()
if getline(".") ==# nerdtree#treeUpDirLine() if getline(".") ==# g:NERDTreeUI.UpDirLine()
return nerdtree#ui_glue#upDir(0) return nerdtree#ui_glue#upDir(0)
endif endif
endfunction endfunction
@ -312,7 +312,7 @@ function! s:handleLeftClick()
endfor endfor
if currentNode.path.isDirectory if currentNode.path.isDirectory
if startToCur =~# nerdtree#treeMarkupReg() && startToCur =~# '[+~▾▸] \?$' if startToCur =~# g:NERDTreeUI.MarkupReg() && startToCur =~# '[+~▾▸] \?$'
call currentNode.activate() call currentNode.activate()
return return
endif endif
@ -320,7 +320,7 @@ function! s:handleLeftClick()
if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3 if (g:NERDTreeMouseMode ==# 2 && currentNode.path.isDirectory) || g:NERDTreeMouseMode ==# 3
let char = strpart(startToCur, strlen(startToCur)-1, 1) let char = strpart(startToCur, strlen(startToCur)-1, 1)
if char !~# nerdtree#treeMarkupReg() if char !~# g:NERDTreeUI.MarkupReg()
if currentNode.path.isDirectory if currentNode.path.isDirectory
call currentNode.activate() call currentNode.activate()
else else

View File

@ -56,7 +56,7 @@ function! s:UI.getPath(ln)
endif endif
endif endif
if line ==# nerdtree#treeUpDirLine() if line ==# s:UI.UpDirLine()
return b:NERDTreeRoot.path.getParent() return b:NERDTreeRoot.path.getParent()
endif endif
@ -146,7 +146,6 @@ function! s:UI.getLineNum(file_node)
return -1 return -1
endfunction endfunction
"FUNCTION: s:UI.getRootLineNum(){{{1 "FUNCTION: s:UI.getRootLineNum(){{{1
"gets the line number of the root node "gets the line number of the root node
function! s:UI.getRootLineNum() function! s:UI.getRootLineNum()
@ -157,9 +156,9 @@ function! s:UI.getRootLineNum()
return rootLine return rootLine
endfunction endfunction
"FUNCTION: s:UI._indentLevelFor(line) {{{2 "FUNCTION: s:UI._indentLevelFor(line) {{{1
function! s:UI._indentLevelFor(line) function! s:UI._indentLevelFor(line)
let level = match(a:line, '[^ \-+~▸▾`|]') / nerdtree#treeWid() let level = match(a:line, '[^ \-+~▸▾`|]') / s:UI.IndentWid()
" check if line includes arrows " check if line includes arrows
if match(a:line, '[▸▾]') > -1 if match(a:line, '[▸▾]') > -1
" decrement level as arrow uses 3 ascii chars " decrement level as arrow uses 3 ascii chars
@ -168,8 +167,21 @@ function! s:UI._indentLevelFor(line)
return level return level
endfunction endfunction
"FUNCTION: s:UI.IndentWid() {{{1
function! s:UI.IndentWid()
return 2
endfunction
"FUNCTION: s:UI.restoreScreenState() {{{2 "FUNCTION: s:UI.MarkupReg() {{{1
function! s:UI.MarkupReg()
if g:NERDTreeDirArrows
return '^\([▾▸] \| \+[▾▸] \| \+\)'
endif
return '^[ `|]*[\-+~]'
endfunction
"FUNCTION: s:UI.restoreScreenState() {{{1
" "
"Sets the screen state back to what it was when nerdtree#saveScreenState was last "Sets the screen state back to what it was when nerdtree#saveScreenState was last
"called. "called.
@ -189,7 +201,7 @@ function! s:UI.restoreScreenState()
let &scrolloff=old_scrolloff let &scrolloff=old_scrolloff
endfunction endfunction
"FUNCTION: s:UI.saveScreenState() {{{2 "FUNCTION: s:UI.saveScreenState() {{{1
"Saves the current cursor position in the current buffer and the window "Saves the current cursor position in the current buffer and the window
"scroll position "scroll position
function! s:UI.saveScreenState() function! s:UI.saveScreenState()
@ -205,7 +217,7 @@ function! s:UI.saveScreenState()
endtry endtry
endfunction endfunction
"FUNCTION: s:UI.render() {{{2 "FUNCTION: s:UI.render() {{{1
function! s:UI.render() function! s:UI.render()
setlocal modifiable setlocal modifiable
@ -232,7 +244,7 @@ function! s:UI.render()
"add the 'up a dir' line "add the 'up a dir' line
if !g:NERDTreeMinimalUI if !g:NERDTreeMinimalUI
call setline(line(".")+1, nerdtree#treeUpDirLine()) call setline(line(".")+1, s:UI.UpDirLine())
call cursor(line(".")+1, col(".")) call cursor(line(".")+1, col("."))
endif endif
@ -330,3 +342,8 @@ function! s:UI.toggleZoom()
let b:NERDTreeZoomed = 1 let b:NERDTreeZoomed = 1
endif endif
endfunction endfunction
"FUNCTION: s:UI.UpDirLine() {{{1
function! s:UI.UpDirLine()
return '.. (up a dir)'
endfunction