nerdtree.vim (3714B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | "CLASS: NERDTree "============================================================ let s:NERDTree = {} let g:NERDTree = s:NERDTree "FUNCTION: s:NERDTree.AddPathFilter() {{{1 function! s:NERDTree.AddPathFilter(callback) call add(s:NERDTree.PathFilters(), a:callback) endfunction "FUNCTION: s:NERDTree.Close() {{{1 "Closes the primary NERD tree window for this tab function! s:NERDTree.Close() if !s:NERDTree.IsOpen() return endif if winnr("$") != 1 if winnr() == s:NERDTree.GetWinNum() call nerdtree#exec("wincmd p") let bufnr = bufnr("") call nerdtree#exec("wincmd p") else let bufnr = bufnr("") endif call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w") close call nerdtree#exec(bufwinnr(bufnr) . " wincmd w") else close endif endfunction "FUNCTION: s:NERDTree.CloseIfQuitOnOpen() {{{1 "Closes the NERD tree window if the close on open option is set function! s:NERDTree.CloseIfQuitOnOpen() if g:NERDTreeQuitOnOpen && s:NERDTree.IsOpen() call s:NERDTree.Close() endif 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 " Returns 1 if a nerd tree root exists in the current buffer function! s:NERDTree.ExistsForBuf() return exists("b:NERDTreeRoot") endfunction " Function: s:NERDTree.ExistsForTab() {{{1 " Returns 1 if a nerd tree root exists in the current tab function! s:NERDTree.ExistsForTab() return exists("t:NERDTreeBufName") endfunction function! s:NERDTree.ForCurrentBuf() if s:NERDTree.ExistsForBuf() return b:NERDTree else return {} endif endfunction "FUNCTION: s:NERDTree.GetWinNum() {{{1 "gets the nerd tree window number for this tab function! s:NERDTree.GetWinNum() if exists("t:NERDTreeBufName") return bufwinnr(t:NERDTreeBufName) else return -1 endif endfunction "FUNCTION: s:NERDTree.IsOpen() {{{1 function! s:NERDTree.IsOpen() return s:NERDTree.GetWinNum() != -1 endfunction "FUNCTION: s:NERDTree.MustBeOpen() {{{1 function! s:NERDTree.MustBeOpen() if !s:NERDTree.IsOpen() throw "NERDTree.TreeNotOpen" endif endfunction "FUNCTION: s:NERDTree.New() {{{1 function! s:NERDTree.New(path) let newObj = copy(self) let newObj.ui = g:NERDTreeUI.New(newObj) let newObj.root = g:NERDTreeDirNode.New(a:path) return newObj endfunction "FUNCTION: s:NERDTree.PathFilters() {{{1 function! s:NERDTree.PathFilters() if !exists('s:NERDTree._PathFilters') let s:NERDTree._PathFilters = [] endif return s:NERDTree._PathFilters endfunction "FUNCTION: s:NERDTree.render() {{{1 "A convenience function - since this is called often function! s:NERDTree.render() call self.ui.render() endfunction |