2014-08-03 18:02:51 -04:00
|
|
|
"CLASS: NERDTree
|
|
|
|
"============================================================
|
|
|
|
let s:NERDTree = {}
|
|
|
|
let g:NERDTree = s:NERDTree
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
"FUNCTION: s:NERDTree.AddPathFilter() {{{1
|
|
|
|
function! s:NERDTree.AddPathFilter(callback)
|
|
|
|
call add(s:NERDTree.PathFilters(), a:callback)
|
|
|
|
endfunction
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
"FUNCTION: s:NERDTree.changeRoot(node) {{{1
|
|
|
|
function! s:NERDTree.changeRoot(node)
|
|
|
|
if a:node.path.isDirectory
|
|
|
|
let self.root = a:node
|
|
|
|
else
|
|
|
|
call a:node.cacheParent()
|
|
|
|
let self.root = a:node.parent
|
|
|
|
endif
|
|
|
|
|
|
|
|
call self.root.open()
|
|
|
|
|
|
|
|
"change dir to the dir of the new root if instructed to
|
2019-11-16 10:28:42 -05:00
|
|
|
if g:NERDTreeChDirMode >= 2
|
2017-11-24 08:54:40 -05:00
|
|
|
call self.root.path.changeToDir()
|
2015-12-08 08:20:04 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
call self.render()
|
|
|
|
call self.root.putCursorHere(0, 0)
|
|
|
|
|
2020-12-04 16:15:32 -05:00
|
|
|
if exists('#User#NERDTreeNewRoot')
|
|
|
|
doautocmd User NERDTreeNewRoot
|
|
|
|
endif
|
2015-12-08 08:20:04 -05:00
|
|
|
endfunction
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
"FUNCTION: s:NERDTree.Close() {{{1
|
2015-12-08 08:20:04 -05:00
|
|
|
"Closes the tab tree window for this tab
|
2015-07-13 06:22:46 -04:00
|
|
|
function! s:NERDTree.Close()
|
|
|
|
if !s:NERDTree.IsOpen()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
if winnr('$') !=# 1
|
2018-02-04 06:35:08 -05:00
|
|
|
" Use the window ID to identify the currently active window or fall
|
|
|
|
" back on the buffer ID if win_getid/win_gotoid are not available, in
|
|
|
|
" which case we'll focus an arbitrary window showing the buffer.
|
|
|
|
let l:useWinId = exists('*win_getid') && exists('*win_gotoid')
|
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
if winnr() ==# s:NERDTree.GetWinNum()
|
|
|
|
call nerdtree#exec('wincmd p', 1)
|
|
|
|
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr('')
|
|
|
|
call nerdtree#exec('wincmd p', 1)
|
2015-07-13 06:22:46 -04:00
|
|
|
else
|
2020-01-07 07:45:07 -05:00
|
|
|
let l:activeBufOrWin = l:useWinId ? win_getid() : bufnr('')
|
2015-07-13 06:22:46 -04:00
|
|
|
endif
|
|
|
|
|
2020-01-07 07:45:07 -05:00
|
|
|
call nerdtree#exec(s:NERDTree.GetWinNum() . ' wincmd w', 1)
|
|
|
|
call nerdtree#exec('close', 0)
|
2018-02-04 06:35:08 -05:00
|
|
|
if l:useWinId
|
2020-01-07 07:45:07 -05:00
|
|
|
call nerdtree#exec('call win_gotoid(' . l:activeBufOrWin . ')', 0)
|
2018-02-04 06:35:08 -05:00
|
|
|
else
|
2020-01-07 07:45:07 -05:00
|
|
|
call nerdtree#exec(bufwinnr(l:activeBufOrWin) . ' wincmd w', 0)
|
2018-02-04 06:35:08 -05:00
|
|
|
endif
|
2015-07-13 06:22:46 -04:00
|
|
|
else
|
|
|
|
close
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: s:NERDTree.CursorToBookmarkTable(){{{1
|
|
|
|
"Places the cursor at the top of the bookmarks table
|
|
|
|
function! s:NERDTree.CursorToBookmarkTable()
|
2015-12-08 08:20:04 -05:00
|
|
|
if !b:NERDTree.ui.getShowBookmarks()
|
2020-01-07 07:45:07 -05:00
|
|
|
throw 'NERDTree.IllegalOperationError: cant find bookmark table, bookmarks arent active'
|
2015-07-13 06:22:46 -04:00
|
|
|
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
|
2020-01-07 07:45:07 -05:00
|
|
|
throw 'NERDTree.BookmarkTableNotFoundError: didnt find the bookmarks table'
|
2015-07-13 06:22:46 -04:00
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
call cursor(line, 2)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: s:NERDTree.CursorToTreeWin(){{{1
|
|
|
|
"Places the cursor in the nerd tree window
|
2020-05-10 10:24:38 -04:00
|
|
|
function! s:NERDTree.CursorToTreeWin(...)
|
2015-07-13 06:22:46 -04:00
|
|
|
call g:NERDTree.MustBeOpen()
|
2020-05-10 10:24:38 -04:00
|
|
|
call nerdtree#exec(g:NERDTree.GetWinNum() . 'wincmd w', a:0 >0 ? a:1 : 1)
|
2015-07-13 06:22:46 -04:00
|
|
|
endfunction
|
|
|
|
|
2014-08-03 18:02:51 -04:00
|
|
|
" Function: s:NERDTree.ExistsForBuffer() {{{1
|
|
|
|
" Returns 1 if a nerd tree root exists in the current buffer
|
|
|
|
function! s:NERDTree.ExistsForBuf()
|
2020-01-07 07:45:07 -05:00
|
|
|
return exists('b:NERDTree')
|
2014-08-03 18:02:51 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: s:NERDTree.ExistsForTab() {{{1
|
|
|
|
" Returns 1 if a nerd tree root exists in the current tab
|
|
|
|
function! s:NERDTree.ExistsForTab()
|
2020-01-07 07:45:07 -05:00
|
|
|
if !exists('t:NERDTreeBufName')
|
2015-12-08 08:20:04 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
"check b:NERDTree is still there and hasn't been e.g. :bdeleted
|
|
|
|
return !empty(getbufvar(bufnr(t:NERDTreeBufName), 'NERDTree'))
|
2014-08-03 18:02:51 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:NERDTree.ForCurrentBuf()
|
|
|
|
if s:NERDTree.ExistsForBuf()
|
|
|
|
return b:NERDTree
|
|
|
|
else
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
"FUNCTION: s:NERDTree.ForCurrentTab() {{{1
|
|
|
|
function! s:NERDTree.ForCurrentTab()
|
|
|
|
if !s:NERDTree.ExistsForTab()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let bufnr = bufnr(t:NERDTreeBufName)
|
2020-01-07 07:45:07 -05:00
|
|
|
return getbufvar(bufnr, 'NERDTree')
|
2015-12-08 08:20:04 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: s:NERDTree.getRoot() {{{1
|
|
|
|
function! s:NERDTree.getRoot()
|
|
|
|
return self.root
|
|
|
|
endfunction
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
"FUNCTION: s:NERDTree.GetWinNum() {{{1
|
|
|
|
"gets the nerd tree window number for this tab
|
|
|
|
function! s:NERDTree.GetWinNum()
|
2020-01-07 07:45:07 -05:00
|
|
|
if exists('t:NERDTreeBufName')
|
2015-07-13 06:22:46 -04:00
|
|
|
return bufwinnr(t:NERDTreeBufName)
|
|
|
|
endif
|
2015-12-08 08:20:04 -05:00
|
|
|
|
2019-11-16 10:28:42 -05:00
|
|
|
" If WindowTree, there is no t:NERDTreeBufName variable. Search all windows.
|
|
|
|
for w in range(1,winnr('$'))
|
|
|
|
if bufname(winbufnr(w)) =~# '^' . g:NERDTreeCreator.BufNamePrefix() . '\d\+$'
|
|
|
|
return w
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
return -1
|
2015-07-13 06:22:46 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: s:NERDTree.IsOpen() {{{1
|
|
|
|
function! s:NERDTree.IsOpen()
|
2020-01-07 07:45:07 -05:00
|
|
|
return s:NERDTree.GetWinNum() !=# -1
|
2015-07-13 06:22:46 -04:00
|
|
|
endfunction
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
"FUNCTION: s:NERDTree.isTabTree() {{{1
|
|
|
|
function! s:NERDTree.isTabTree()
|
2020-01-07 07:45:07 -05:00
|
|
|
return self._type ==# 'tab'
|
2015-12-08 08:20:04 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: s:NERDTree.isWinTree() {{{1
|
|
|
|
function! s:NERDTree.isWinTree()
|
2020-01-07 07:45:07 -05:00
|
|
|
return self._type ==# 'window'
|
2015-12-08 08:20:04 -05:00
|
|
|
endfunction
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
"FUNCTION: s:NERDTree.MustBeOpen() {{{1
|
|
|
|
function! s:NERDTree.MustBeOpen()
|
|
|
|
if !s:NERDTree.IsOpen()
|
2020-01-07 07:45:07 -05:00
|
|
|
throw 'NERDTree.TreeNotOpen'
|
2015-07-13 06:22:46 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: s:NERDTree.New() {{{1
|
2015-12-08 08:20:04 -05:00
|
|
|
function! s:NERDTree.New(path, type)
|
2014-08-03 18:02:51 -04:00
|
|
|
let newObj = copy(self)
|
|
|
|
let newObj.ui = g:NERDTreeUI.New(newObj)
|
2015-12-08 08:20:04 -05:00
|
|
|
let newObj.root = g:NERDTreeDirNode.New(a:path, newObj)
|
|
|
|
let newObj._type = a:type
|
2014-08-03 18:02:51 -04:00
|
|
|
return newObj
|
|
|
|
endfunction
|
|
|
|
|
2015-07-13 06:22:46 -04:00
|
|
|
"FUNCTION: s:NERDTree.PathFilters() {{{1
|
|
|
|
function! s:NERDTree.PathFilters()
|
|
|
|
if !exists('s:NERDTree._PathFilters')
|
|
|
|
let s:NERDTree._PathFilters = []
|
|
|
|
endif
|
|
|
|
return s:NERDTree._PathFilters
|
|
|
|
endfunction
|
|
|
|
|
2015-12-08 08:20:04 -05:00
|
|
|
"FUNCTION: s:NERDTree.previousBuf() {{{1
|
|
|
|
function! s:NERDTree.previousBuf()
|
|
|
|
return self._previousBuf
|
|
|
|
endfunction
|
2015-07-13 06:22:46 -04:00
|
|
|
|
2016-11-09 12:22:55 -05:00
|
|
|
function! s:NERDTree.setPreviousBuf(bnum)
|
|
|
|
let self._previousBuf = a:bnum
|
|
|
|
endfunction
|
|
|
|
|
2014-08-03 18:02:51 -04:00
|
|
|
"FUNCTION: s:NERDTree.render() {{{1
|
|
|
|
"A convenience function - since this is called often
|
|
|
|
function! s:NERDTree.render()
|
|
|
|
call self.ui.render()
|
|
|
|
endfunction
|
2018-02-04 06:35:08 -05:00
|
|
|
|
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|