move some rendering and cursor moving functions out of autoload

This commit is contained in:
Martin Grenfell
2015-05-02 15:24:59 +01:00
parent b0114d202b
commit 8b189cb263
6 changed files with 99 additions and 99 deletions

View File

@@ -128,96 +128,9 @@ function! nerdtree#echoWarning(msg)
echohl normal echohl normal
endfunction endfunction
"FUNCTION: nerdtree#putCursorOnBookmarkTable(){{{2
"Places the cursor at the top of the bookmarks table
function! nerdtree#putCursorOnBookmarkTable()
if !b:NERDTreeShowBookmarks
throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active"
endif
if g:NERDTreeMinimalUI
return cursor(1, 2)
endif
let rootNodeLine = b:NERDTree.ui.getRootLineNum()
let line = 1
while getline(line) !~# '^>-\+Bookmarks-\+$'
let line = line + 1
if line >= rootNodeLine
throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table"
endif
endwhile
call cursor(line, 2)
endfunction
"FUNCTION: nerdtree#putCursorInTreeWin(){{{2
"Places the cursor in the nerd tree window
function! nerdtree#putCursorInTreeWin()
call g:NERDTree.MustBeOpen()
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w")
endfunction
"FUNCTION: nerdtree#renderBookmarks {{{2
function! nerdtree#renderBookmarks()
if g:NERDTreeMinimalUI == 0
call setline(line(".")+1, ">----------Bookmarks----------")
call cursor(line(".")+1, col("."))
endif
for i in g:NERDTreeBookmark.Bookmarks()
call setline(line(".")+1, i.str())
call cursor(line(".")+1, col("."))
endfor
call setline(line(".")+1, '')
call cursor(line(".")+1, col("."))
endfunction
"FUNCTION: nerdtree#renderView {{{2 "FUNCTION: nerdtree#renderView {{{2
function! nerdtree#renderView() function! nerdtree#renderView()
call b:NERDTree.render() call b:NERDTree.render()
endfunction endfunction
"
"FUNCTION: nerdtree#stripMarkupFromLine(line, removeLeadingSpaces){{{2
"returns the given line with all the tree parts stripped off
"
"Args:
"line: the subject line
"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces =
"any spaces before the actual text of the node)
function! nerdtree#stripMarkupFromLine(line, removeLeadingSpaces)
let line = a:line
"remove the tree parts and the leading space
let line = substitute (line, g:NERDTreeUI.MarkupReg(),"","")
"strip off any read only flag
let line = substitute (line, ' \[RO\]', "","")
"strip off any bookmark flags
let line = substitute (line, ' {[^}]*}', "","")
"strip off any executable flags
let line = substitute (line, '*\ze\($\| \)', "","")
"strip off any generic flags
let line = substitute (line, '\[[^]]*\]', "","")
let wasdir = 0
if line =~# '/$'
let wasdir = 1
endif
let line = substitute (line,' -> .*',"","") " remove link to
if wasdir ==# 1
let line = substitute (line, '/\?$', '/', "")
endif
if a:removeLeadingSpaces
let line = substitute (line, '^ *', '', '')
endif
return line
endfunction
" vim: set sw=4 sts=4 et fdm=marker: " vim: set sw=4 sts=4 et fdm=marker:

View File

@@ -278,7 +278,7 @@ function! s:findAndRevealPath()
if !g:NERDTree.IsOpen() if !g:NERDTree.IsOpen()
call g:NERDTreeCreator.TogglePrimary('') call g:NERDTreeCreator.TogglePrimary('')
else else
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
endif endif
let b:NERDTreeShowHidden = g:NERDTreeShowHidden let b:NERDTreeShowHidden = g:NERDTreeShowHidden
call s:chRoot(g:NERDTreeDirNode.New(p.getParent())) call s:chRoot(g:NERDTreeDirNode.New(p.getParent()))
@@ -288,7 +288,7 @@ function! s:findAndRevealPath()
endif endif
endif endif
endif endif
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
call b:NERDTreeRoot.reveal(p) call b:NERDTreeRoot.reveal(p)
if p.isUnixHiddenFile() if p.isUnixHiddenFile()

View File

@@ -35,6 +35,36 @@ function! s:NERDTree.CloseIfQuitOnOpen()
endif endif
endfunction endfunction
"FUNCTION: s:NERDTree.CursorToBookmarkTable(){{{1
"Places the cursor at the top of the bookmarks table
function! s:NERDTree.CursorToBookmarkTable()
if !b:NERDTreeShowBookmarks
throw "NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active"
endif
if g:NERDTreeMinimalUI
return cursor(1, 2)
endif
let rootNodeLine = b:NERDTree.ui.getRootLineNum()
let line = 1
while getline(line) !~# '^>-\+Bookmarks-\+$'
let line = line + 1
if line >= rootNodeLine
throw "NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table"
endif
endwhile
call cursor(line, 2)
endfunction
"FUNCTION: s:NERDTree.CursorToTreeWin(){{{1
"Places the cursor in the nerd tree window
function! s:NERDTree.CursorToTreeWin()
call g:NERDTree.MustBeOpen()
call nerdtree#exec(g:NERDTree.GetWinNum() . "wincmd w")
endfunction
" Function: s:NERDTree.ExistsForBuffer() {{{1 " Function: s:NERDTree.ExistsForBuffer() {{{1
" Returns 1 if a nerd tree root exists in the current buffer " Returns 1 if a nerd tree root exists in the current buffer
function! s:NERDTree.ExistsForBuf() function! s:NERDTree.ExistsForBuf()

View File

@@ -189,7 +189,7 @@ function! s:Opener._newSplit()
try try
exec(splitMode." sp ") exec(splitMode." sp ")
catch /^Vim\%((\a\+)\)\=:E37/ catch /^Vim\%((\a\+)\)\=:E37/
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified." throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
catch /^Vim\%((\a\+)\)\=:/ catch /^Vim\%((\a\+)\)\=:/
"do nothing "do nothing
@@ -219,7 +219,7 @@ function! s:Opener._newVSplit()
vnew vnew
"resize the nerd tree back to the original size "resize the nerd tree back to the original size
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
exec("silent vertical resize ". winwidth) exec("silent vertical resize ". winwidth)
call nerdtree#exec('wincmd p') call nerdtree#exec('wincmd p')
endfunction endfunction
@@ -288,7 +288,7 @@ function! s:Opener._previousWindow()
call nerdtree#exec('wincmd p') call nerdtree#exec('wincmd p')
endif endif
catch /^Vim\%((\a\+)\)\=:E37/ catch /^Vim\%((\a\+)\)\=:E37/
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified." throw "NERDTree.FileAlreadyOpenAndModifiedError: ". self._path.str() ." is already open and modified."
catch /^Vim\%((\a\+)\)\=:/ catch /^Vim\%((\a\+)\)\=:/
echo v:exception echo v:exception

View File

@@ -171,7 +171,7 @@ function! s:UI.getPath(ln)
let indent = self._indentLevelFor(line) let indent = self._indentLevelFor(line)
"remove the tree parts and the leading space "remove the tree parts and the leading space
let curFile = nerdtree#stripMarkupFromLine(line, 0) let curFile = self._stripMarkup(line, 0)
let wasdir = 0 let wasdir = 0
if curFile =~# '/$' if curFile =~# '/$'
@@ -184,7 +184,7 @@ function! s:UI.getPath(ln)
while lnum > 0 while lnum > 0
let lnum = lnum - 1 let lnum = lnum - 1
let curLine = getline(lnum) let curLine = getline(lnum)
let curLineStripped = nerdtree#stripMarkupFromLine(curLine, 1) let curLineStripped = self._stripMarkup(curLine, 1)
"have we reached the top of the tree? "have we reached the top of the tree?
if lnum == rootLine if lnum == rootLine
@@ -235,7 +235,7 @@ function! s:UI.getLineNum(file_node)
let indent = self._indentLevelFor(curLine) let indent = self._indentLevelFor(curLine)
if indent ==# curPathComponent if indent ==# curPathComponent
let curLine = nerdtree#stripMarkupFromLine(curLine, 1) let curLine = self._stripMarkup(curLine, 1)
let curPath = join(pathcomponents, '/') . '/' . curLine let curPath = join(pathcomponents, '/') . '/' . curLine
if stridx(fullpath, curPath, 0) ==# 0 if stridx(fullpath, curPath, 0) ==# 0
@@ -289,6 +289,23 @@ function! s:UI.MarkupReg()
return '^[ `|]*[\-+~]' return '^[ `|]*[\-+~]'
endfunction endfunction
"FUNCTION: s:UI._renderBookmarks {{{1
function! s:UI._renderBookmarks()
if g:NERDTreeMinimalUI == 0
call setline(line(".")+1, ">----------Bookmarks----------")
call cursor(line(".")+1, col("."))
endif
for i in g:NERDTreeBookmark.Bookmarks()
call setline(line(".")+1, i.str())
call cursor(line(".")+1, col("."))
endfor
call setline(line(".")+1, '')
call cursor(line(".")+1, col("."))
endfunction
"FUNCTION: s:UI.restoreScreenState() {{{1 "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
@@ -315,7 +332,7 @@ endfunction
function! s:UI.saveScreenState() function! s:UI.saveScreenState()
let win = winnr() let win = winnr()
try try
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
let self._screenState = {} let self._screenState = {}
let self._screenState['oldPos'] = getpos(".") let self._screenState['oldPos'] = getpos(".")
let self._screenState['oldTopLine'] = line("w0") let self._screenState['oldTopLine'] = line("w0")
@@ -325,6 +342,46 @@ function! s:UI.saveScreenState()
endtry endtry
endfunction endfunction
"FUNCTION: s:UI._stripMarkup(line, removeLeadingSpaces){{{1
"returns the given line with all the tree parts stripped off
"
"Args:
"line: the subject line
"removeLeadingSpaces: 1 if leading spaces are to be removed (leading spaces =
"any spaces before the actual text of the node)
function! s:UI._stripMarkup(line, removeLeadingSpaces)
let line = a:line
"remove the tree parts and the leading space
let line = substitute (line, g:NERDTreeUI.MarkupReg(),"","")
"strip off any read only flag
let line = substitute (line, ' \[RO\]', "","")
"strip off any bookmark flags
let line = substitute (line, ' {[^}]*}', "","")
"strip off any executable flags
let line = substitute (line, '*\ze\($\| \)', "","")
"strip off any generic flags
let line = substitute (line, '\[[^]]*\]', "","")
let wasdir = 0
if line =~# '/$'
let wasdir = 1
endif
let line = substitute (line,' -> .*',"","") " remove link to
if wasdir ==# 1
let line = substitute (line, '/\?$', '/', "")
endif
if a:removeLeadingSpaces
let line = substitute (line, '^ *', '', '')
endif
return line
endfunction
"FUNCTION: s:UI.render() {{{1 "FUNCTION: s:UI.render() {{{1
function! s:UI.render() function! s:UI.render()
setlocal modifiable setlocal modifiable
@@ -347,7 +404,7 @@ function! s:UI.render()
endif endif
if b:NERDTreeShowBookmarks if b:NERDTreeShowBookmarks
call nerdtree#renderBookmarks() call self._renderBookmarks()
endif endif
"add the 'up a dir' line "add the 'up a dir' line
@@ -415,7 +472,7 @@ function! s:UI.toggleShowBookmarks()
let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks let b:NERDTreeShowBookmarks = !b:NERDTreeShowBookmarks
if b:NERDTreeShowBookmarks if b:NERDTreeShowBookmarks
call b:NERDTree.render() call b:NERDTree.render()
call nerdtree#putCursorOnBookmarkTable() call g:NERDTree.CursorToBookmarkTable()
else else
call b:NERDTree.ui.renderViewSavingPosition() call b:NERDTree.ui.renderViewSavingPosition()
endif endif

View File

@@ -186,7 +186,7 @@ endfunction
function! NERDTreeFocus() function! NERDTreeFocus()
if g:NERDTree.IsOpen() if g:NERDTree.IsOpen()
call nerdtree#putCursorInTreeWin() call g:NERDTree.CursorToTreeWin()
else else
call g:NERDTreeCreator.TogglePrimary("") call g:NERDTreeCreator.TogglePrimary("")
endif endif