1 if exists('g:loaded_nerdtree_autoload') 2 finish 3 endif 4 let g:loaded_nerdtree_autoload = 1 5 6 let s:rootNERDTreePath = resolve(expand('<sfile>:p:h:h')) 7 8 "FUNCTION: nerdtree#version(...) {{{1 9 " If any value is given as an argument, the entire line of text from the 10 " change log is shown for the current version; otherwise, only the version 11 " number is shown. 12 function! nerdtree#version(...) abort 13 let l:text = 'Unknown' 14 try 15 let l:changelog = readfile(join([s:rootNERDTreePath, 'CHANGELOG.md'], nerdtree#slash())) 16 let l:line = 0 17 while l:line <= len(l:changelog) 18 if l:changelog[l:line] =~# '\d\+\.\d\+' 19 let l:text = substitute(l:changelog[l:line], '.*\(\d\+.\d\+\).*', '\1', '') 20 let l:text .= substitute(l:changelog[l:line+1], '^.\{-}\(\.\d\+\).\{-}:\(.*\)', a:0>0 ? '\1:\2' : '\1', '') 21 break 22 endif 23 let l:line += 1 24 endwhile 25 catch 26 endtry 27 return l:text 28 endfunction 29 30 " SECTION: General Functions {{{1 31 "============================================================ 32 33 " FUNCTION: nerdtree#closeTreeOnOpen() {{{2 34 function! nerdtree#closeTreeOnOpen() abort 35 return g:NERDTreeQuitOnOpen == 1 || g:NERDTreeQuitOnOpen == 3 36 endfunction 37 38 " FUNCTION: nerdtree#closeBookmarksOnOpen() {{{2 39 function! nerdtree#closeBookmarksOnOpen() abort 40 return g:NERDTreeQuitOnOpen == 2 || g:NERDTreeQuitOnOpen == 3 41 endfunction 42 43 " FUNCTION: nerdtree#slash() {{{2 44 " Return the path separator used by the underlying file system. Special 45 " consideration is taken for the use of the 'shellslash' option on Windows 46 " systems. 47 function! nerdtree#slash() abort 48 if nerdtree#runningWindows() 49 if exists('+shellslash') && &shellslash 50 return '/' 51 endif 52 53 return '\' 54 endif 55 56 return '/' 57 endfunction 58 59 "FUNCTION: nerdtree#checkForBrowse(dir) {{{2 60 "inits a window tree in the current buffer if appropriate 61 function! nerdtree#checkForBrowse(dir) abort 62 if !isdirectory(a:dir) 63 return 64 endif 65 66 if s:reuseWin(a:dir) 67 return 68 endif 69 70 call g:NERDTreeCreator.CreateWindowTree(a:dir) 71 endfunction 72 73 "FUNCTION: s:reuseWin(dir) {{{2 74 "finds a NERDTree buffer with root of dir, and opens it. 75 function! s:reuseWin(dir) abort 76 let path = g:NERDTreePath.New(fnamemodify(a:dir, ':p')) 77 78 for i in range(1, bufnr('$')) 79 unlet! nt 80 let nt = getbufvar(i, 'NERDTree') 81 if empty(nt) 82 continue 83 endif 84 85 if nt.isWinTree() && nt.root.path.equals(path) 86 call nt.setPreviousBuf(bufnr('#')) 87 exec 'buffer ' . i 88 return 1 89 endif 90 endfor 91 92 return 0 93 endfunction 94 95 " FUNCTION: nerdtree#completeBookmarks(A,L,P) {{{2 96 " completion function for the bookmark commands 97 function! nerdtree#completeBookmarks(A,L,P) abort 98 return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"') 99 endfunction 100 101 "FUNCTION: nerdtree#compareNodes(n1, n2) {{{2 102 function! nerdtree#compareNodes(n1, n2) abort 103 return nerdtree#compareNodePaths(a:n1.path, a:n2.path) 104 endfunction 105 106 "FUNCTION: nerdtree#compareNodePaths(p1, p2) {{{2 107 function! nerdtree#compareNodePaths(p1, p2) abort 108 let sortKey1 = a:p1.getSortKey() 109 let sortKey2 = a:p2.getSortKey() 110 let i = 0 111 while i < min([len(sortKey1), len(sortKey2)]) 112 " Compare chunks upto common length. 113 " If chunks have different type, the one which has 114 " integer type is the lesser. 115 if type(sortKey1[i]) == type(sortKey2[i]) 116 if sortKey1[i] <# sortKey2[i] 117 return - 1 118 elseif sortKey1[i] ># sortKey2[i] 119 return 1 120 endif 121 elseif type(sortKey1[i]) == type(0) 122 return -1 123 elseif type(sortKey2[i]) == type(0) 124 return 1 125 endif 126 let i += 1 127 endwhile 128 129 " Keys are identical upto common length. 130 " The key which has smaller chunks is the lesser one. 131 if len(sortKey1) < len(sortKey2) 132 return -1 133 elseif len(sortKey1) > len(sortKey2) 134 return 1 135 else 136 return 0 137 endif 138 endfunction 139 140 " FUNCTION: nerdtree#deprecated(func, [msg]) {{{2 141 " Issue a deprecation warning for a:func. If a second arg is given, use this 142 " as the deprecation message 143 function! nerdtree#deprecated(func, ...) abort 144 let msg = a:0 ? a:func . ' ' . a:1 : a:func . ' is deprecated' 145 146 if !exists('s:deprecationWarnings') 147 let s:deprecationWarnings = {} 148 endif 149 if !has_key(s:deprecationWarnings, a:func) 150 let s:deprecationWarnings[a:func] = 1 151 echomsg msg 152 endif 153 endfunction 154 155 " FUNCTION: nerdtree#exec(cmd, ignoreAll) {{{2 156 " Same as :exec cmd but, if ignoreAll is TRUE, set eventignore=all for the duration 157 function! nerdtree#exec(cmd, ignoreAll) abort 158 let old_ei = &eventignore 159 if a:ignoreAll 160 set eventignore=all 161 endif 162 try 163 exec a:cmd 164 finally 165 let &eventignore = old_ei 166 endtry 167 endfunction 168 169 " FUNCTION: nerdtree#has_opt(options, name) {{{2 170 function! nerdtree#has_opt(options, name) abort 171 return has_key(a:options, a:name) && a:options[a:name] ==# 1 172 endfunction 173 174 " FUNCTION: nerdtree#loadClassFiles() {{{2 175 function! nerdtree#loadClassFiles() abort 176 runtime lib/nerdtree/path.vim 177 runtime lib/nerdtree/menu_controller.vim 178 runtime lib/nerdtree/menu_item.vim 179 runtime lib/nerdtree/key_map.vim 180 runtime lib/nerdtree/bookmark.vim 181 runtime lib/nerdtree/tree_file_node.vim 182 runtime lib/nerdtree/tree_dir_node.vim 183 runtime lib/nerdtree/opener.vim 184 runtime lib/nerdtree/creator.vim 185 runtime lib/nerdtree/flag_set.vim 186 runtime lib/nerdtree/nerdtree.vim 187 runtime lib/nerdtree/ui.vim 188 runtime lib/nerdtree/event.vim 189 runtime lib/nerdtree/notifier.vim 190 endfunction 191 192 " FUNCTION: nerdtree#postSourceActions() {{{2 193 function! nerdtree#postSourceActions() abort 194 call g:NERDTreeBookmark.CacheBookmarks(1) 195 call nerdtree#ui_glue#createDefaultBindings() 196 197 "load all nerdtree plugins 198 runtime! nerdtree_plugin/**/*.vim 199 endfunction 200 201 "FUNCTION: nerdtree#runningWindows(dir) {{{2 202 function! nerdtree#runningWindows() abort 203 return has('win16') || has('win32') || has('win64') 204 endfunction 205 206 "FUNCTION: nerdtree#runningCygwin(dir) {{{2 207 function! nerdtree#runningCygwin() abort 208 return has('win32unix') 209 endfunction 210 211 " SECTION: View Functions {{{1 212 "============================================================ 213 214 "FUNCTION: nerdtree#echo {{{2 215 "A wrapper for :echo. Appends 'NERDTree:' on the front of all messages 216 " 217 "Args: 218 "msg: the message to echo 219 function! nerdtree#echo(msg) abort 220 redraw 221 echomsg empty(a:msg) ? '' : ('NERDTree: ' . a:msg) 222 endfunction 223 224 "FUNCTION: nerdtree#echoError {{{2 225 "Wrapper for nerdtree#echo, sets the message type to errormsg for this message 226 "Args: 227 "msg: the message to echo 228 function! nerdtree#echoError(msg) abort 229 echohl errormsg 230 call nerdtree#echo(a:msg) 231 echohl normal 232 endfunction 233 234 "FUNCTION: nerdtree#echoWarning {{{2 235 "Wrapper for nerdtree#echo, sets the message type to warningmsg for this message 236 "Args: 237 "msg: the message to echo 238 function! nerdtree#echoWarning(msg) abort 239 echohl warningmsg 240 call nerdtree#echo(a:msg) 241 echohl normal 242 endfunction 243 244 "FUNCTION: nerdtree#renderView {{{2 245 function! nerdtree#renderView() abort 246 call b:NERDTree.render() 247 endfunction 248 249 " vim: set sw=4 sts=4 et fdm=marker:
