2013-01-05 09:08:06 +08:00
|
|
|
if exists("g:loaded_nerdtree_autoload")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_nerdtree_autoload = 1
|
|
|
|
|
|
|
|
function! nerdtree#version()
|
2015-11-14 00:57:21 +08:00
|
|
|
return '5.0.0'
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" SECTION: General Functions {{{1
|
|
|
|
"============================================================
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#checkForBrowse(dir) {{{2
|
2015-11-14 19:50:01 +08:00
|
|
|
"inits a window tree in the current buffer if appropriate
|
2013-01-05 09:08:06 +08:00
|
|
|
function! nerdtree#checkForBrowse(dir)
|
2016-10-14 23:34:08 +08:00
|
|
|
if !isdirectory(a:dir)
|
|
|
|
return
|
2013-01-05 09:08:06 +08:00
|
|
|
endif
|
2016-10-14 23:34:08 +08:00
|
|
|
|
|
|
|
if s:reuseWin(a:dir)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
call g:NERDTreeCreator.CreateWindowTree(a:dir)
|
|
|
|
endfunction
|
|
|
|
|
2016-10-17 22:05:50 +08:00
|
|
|
"FUNCTION: s:reuseWin(dir) {{{2
|
|
|
|
"finds a NERDTree buffer with root of dir, and opens it.
|
2016-10-14 23:34:08 +08:00
|
|
|
function! s:reuseWin(dir) abort
|
|
|
|
let path = g:NERDTreePath.New(fnamemodify(a:dir, ":p"))
|
|
|
|
|
|
|
|
for i in range(1, bufnr("$"))
|
2016-10-17 22:05:50 +08:00
|
|
|
unlet! nt
|
2016-10-14 23:34:08 +08:00
|
|
|
let nt = getbufvar(i, "NERDTree")
|
|
|
|
if empty(nt)
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
|
|
|
if nt.isWinTree() && nt.root.path.equals(path)
|
2016-10-21 21:47:09 +08:00
|
|
|
call nt.setPreviousBuf(bufnr("#"))
|
2016-10-14 23:34:08 +08:00
|
|
|
exec "buffer " . i
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return 0
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#completeBookmarks(A,L,P) {{{2
|
|
|
|
" completion function for the bookmark commands
|
|
|
|
function! nerdtree#completeBookmarks(A,L,P)
|
|
|
|
return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#compareNodes(dir) {{{2
|
|
|
|
function! nerdtree#compareNodes(n1, n2)
|
|
|
|
return a:n1.path.compareTo(a:n2.path)
|
|
|
|
endfunction
|
|
|
|
|
2015-05-11 11:56:08 +08:00
|
|
|
"FUNCTION: nerdtree#compareNodesBySortKey(n1, n2) {{{2
|
|
|
|
function! nerdtree#compareNodesBySortKey(n1, n2)
|
2016-01-19 16:21:13 +08:00
|
|
|
let sortKey1 = a:n1.path.getSortKey()
|
|
|
|
let sortKey2 = a:n2.path.getSortKey()
|
|
|
|
|
|
|
|
let i = 0
|
|
|
|
while i < min([len(sortKey1), len(sortKey2)])
|
|
|
|
" Compare chunks upto common length.
|
|
|
|
" If chunks have different type, the one which has
|
|
|
|
" integer type is the lesser.
|
|
|
|
if type(sortKey1[i]) == type(sortKey2[i])
|
|
|
|
if sortKey1[i] <# sortKey2[i]
|
|
|
|
return - 1
|
|
|
|
elseif sortKey1[i] ># sortKey2[i]
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
elseif sortKey1[i] == type(0)
|
|
|
|
return -1
|
|
|
|
elseif sortKey2[i] == type(0)
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
let i = i + 1
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
" Keys are identical upto common length.
|
|
|
|
" The key which has smaller chunks is the lesser one.
|
|
|
|
if len(sortKey1) < len(sortKey2)
|
2015-05-09 22:38:16 +08:00
|
|
|
return -1
|
2016-01-19 16:21:13 +08:00
|
|
|
elseif len(sortKey1) > len(sortKey2)
|
2015-05-09 22:38:16 +08:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" FUNCTION: nerdtree#deprecated(func, [msg]) {{{2
|
|
|
|
" Issue a deprecation warning for a:func. If a second arg is given, use this
|
|
|
|
" as the deprecation message
|
|
|
|
function! nerdtree#deprecated(func, ...)
|
|
|
|
let msg = a:0 ? a:func . ' ' . a:1 : a:func . ' is deprecated'
|
|
|
|
|
|
|
|
if !exists('s:deprecationWarnings')
|
|
|
|
let s:deprecationWarnings = {}
|
|
|
|
endif
|
|
|
|
if !has_key(s:deprecationWarnings, a:func)
|
|
|
|
let s:deprecationWarnings[a:func] = 1
|
|
|
|
echomsg msg
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#exec(cmd) {{{2
|
2017-05-18 22:02:02 +08:00
|
|
|
" Same as :exec cmd but with eventignore set for the duration
|
|
|
|
" to disable the autocommands used by NERDTree (BufEnter,
|
|
|
|
" BufLeave and VimEnter)
|
2013-01-05 09:08:06 +08:00
|
|
|
function! nerdtree#exec(cmd)
|
|
|
|
let old_ei = &ei
|
2016-05-06 00:32:19 +08:00
|
|
|
set ei=BufEnter,BufLeave,VimEnter
|
2013-01-05 09:08:06 +08:00
|
|
|
exec a:cmd
|
|
|
|
let &ei = old_ei
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" FUNCTION: nerdtree#has_opt(options, name) {{{2
|
|
|
|
function! nerdtree#has_opt(options, name)
|
|
|
|
return has_key(a:options, a:name) && a:options[a:name] == 1
|
|
|
|
endfunction
|
|
|
|
|
2013-04-14 03:32:25 +08:00
|
|
|
" FUNCTION: nerdtree#loadClassFiles() {{{2
|
|
|
|
function! nerdtree#loadClassFiles()
|
|
|
|
runtime lib/nerdtree/path.vim
|
|
|
|
runtime lib/nerdtree/menu_controller.vim
|
|
|
|
runtime lib/nerdtree/menu_item.vim
|
|
|
|
runtime lib/nerdtree/key_map.vim
|
|
|
|
runtime lib/nerdtree/bookmark.vim
|
|
|
|
runtime lib/nerdtree/tree_file_node.vim
|
|
|
|
runtime lib/nerdtree/tree_dir_node.vim
|
|
|
|
runtime lib/nerdtree/opener.vim
|
|
|
|
runtime lib/nerdtree/creator.vim
|
2014-07-06 03:51:21 +08:00
|
|
|
runtime lib/nerdtree/flag_set.vim
|
2014-07-08 05:59:28 +08:00
|
|
|
runtime lib/nerdtree/nerdtree.vim
|
|
|
|
runtime lib/nerdtree/ui.vim
|
2014-07-18 03:16:57 +08:00
|
|
|
runtime lib/nerdtree/event.vim
|
|
|
|
runtime lib/nerdtree/notifier.vim
|
2013-04-14 03:32:25 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" FUNCTION: nerdtree#postSourceActions() {{{2
|
|
|
|
function! nerdtree#postSourceActions()
|
2015-12-03 05:16:34 +08:00
|
|
|
call g:NERDTreeBookmark.CacheBookmarks(1)
|
2014-07-08 02:36:34 +08:00
|
|
|
call nerdtree#ui_glue#createDefaultBindings()
|
2013-01-05 09:08:06 +08:00
|
|
|
|
|
|
|
"load all nerdtree plugins
|
|
|
|
runtime! nerdtree_plugin/**/*.vim
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#runningWindows(dir) {{{2
|
|
|
|
function! nerdtree#runningWindows()
|
2017-05-23 19:15:35 +08:00
|
|
|
return has("win16") || has("win32") || has("win64")
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
2017-10-27 15:06:51 +08:00
|
|
|
"FUNCTION: nerdtree#runningCygwin(dir) {{{2
|
|
|
|
function! nerdtree#runningCygwin()
|
|
|
|
return has("win32unix")
|
|
|
|
endfunction
|
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
" SECTION: View Functions {{{1
|
|
|
|
"============================================================
|
2014-07-08 03:12:05 +08:00
|
|
|
|
2013-01-05 09:08:06 +08:00
|
|
|
"FUNCTION: nerdtree#echo {{{2
|
|
|
|
"A wrapper for :echo. Appends 'NERDTree:' on the front of all messages
|
|
|
|
"
|
|
|
|
"Args:
|
|
|
|
"msg: the message to echo
|
|
|
|
function! nerdtree#echo(msg)
|
|
|
|
redraw
|
|
|
|
echomsg "NERDTree: " . a:msg
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#echoError {{{2
|
|
|
|
"Wrapper for nerdtree#echo, sets the message type to errormsg for this message
|
|
|
|
"Args:
|
|
|
|
"msg: the message to echo
|
|
|
|
function! nerdtree#echoError(msg)
|
|
|
|
echohl errormsg
|
|
|
|
call nerdtree#echo(a:msg)
|
|
|
|
echohl normal
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#echoWarning {{{2
|
|
|
|
"Wrapper for nerdtree#echo, sets the message type to warningmsg for this message
|
|
|
|
"Args:
|
|
|
|
"msg: the message to echo
|
|
|
|
function! nerdtree#echoWarning(msg)
|
|
|
|
echohl warningmsg
|
|
|
|
call nerdtree#echo(a:msg)
|
|
|
|
echohl normal
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
"FUNCTION: nerdtree#renderView {{{2
|
|
|
|
function! nerdtree#renderView()
|
2014-07-08 05:59:28 +08:00
|
|
|
call b:NERDTree.render()
|
2013-01-05 09:08:06 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|